Make WordPress Core

Opened 4 years ago

Last modified 4 years ago

#51365 new enhancement

Introduce dedicated function to check if post meta exists

Reported by: daveyjake's profile DaveyJake Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: dev-feedback
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 (1)

#1 @davidbaumwald
4 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 4 years ago by davidbaumwald (previous) (diff)
Note: See TracTickets for help on using tickets.