Opened 5 years ago
Last modified 4 months ago
#51365 new enhancement
Introduce dedicated function to check if post meta exists
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | 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 (2)
#1
@
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
#2
@
4 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. 😃
Note: See
TracTickets for help on using
tickets.
@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-feedbackto see if we can gather some opinions on whether this is needed.