Make WordPress Core

Opened 5 years ago

Closed 7 weeks ago

#51365 closed enhancement (wontfix)

Introduce dedicated function to check if post meta exists

Reported by: daveyjake's profile DaveyJake Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: dev-feedback close
Focuses: Cc:

Description

Just wanted to suggest a simple function that checks for pre-existing metadata for the native post post type.

Looking forward to getting more involved and collaborating with everyone!

<?php
/**
 * Check if post has pre-existing metadata.
 *
 * @since 5.5.2
 *
 * @see metadata_exists()
 *
 * @param int    $post_id  The post ID.
 * @param string $meta_key The meta key to look for.
 *
 * @return bool            True if key is found. False if not.
 */
function post_meta_exists( $post_id, $meta_key ) {
    if ( metadata_exists( 'post', $post_id, $meta_key ) ) {
        return true;
    }

    return false;
}

Change History (4)

#1 @davidbaumwald
5 years ago

  • Focuses administration template removed
  • Keywords dev-feedback added
  • Summary changed from This is my very first suggestion. I hope I'm in the right place? to Introduce dedicated function to check if post meta exists

@DaveyJake Yes, this is the right place! Thanks for the ticket. I'm updating the title of the ticket to reflect its nature. Marking this for dev-feedback to see if we can gather some opinions on whether this is needed.

Last edited 5 years ago by davidbaumwald (previous) (diff)

#2 @callumbw95
7 months ago

  • Keywords close added

Hi @DaveyJake,

I have taken a look into this, and I am not sure there is much need for this wrapper function within core. My reasoning is that your function can be condensed down to the following:

<?php
function post_meta_exists( $post_id, $meta_key ) {
    return metadata_exists( 'post', $post_id, $meta_key );
}

From the above code it raises the question why not just use metadata_exists()?

As I am not sure the reason to add this wrapper function in to core, I am going to mark this ticket with the close tag. However, please feel free to reopen this ticket if you wish to continue this ticket further. 😃

This ticket was mentioned in Slack in #core by sirlouen. View the logs.


7 weeks ago

#4 @SirLouen
7 weeks ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Following the suggestion by @callumbw95 I think its time to close this as 5 months have passed and there have not been any additional feedback provided

@DaveyJake feel free to comment whenever you want and provide more information and me or Callum, will be happy to continue digging into this problem if it still exists

Note: See TracTickets for help on using tickets.