I want to use Unique IDs like YouTube video IDs and WordPress post IDs in a custom field ‘youtube_id’. I just created a front-end add post page and want to check if ‘youtube_id’ used or not used in a older post.
$title = 'blah blah blah';
$different=mysql_query("SELECT post_title FROM wp_posts WHERE post_title='$title'");
if(mysql_num_rows($different)>0) {
echo 'Dude, we already have this post.';
}
this code looks for post title is unique or not. I need something similar with this. But I need to use postmeta, not post_title.
Any idea to check it with WordPress functions or mysql?
PS: Sorry for my poor English.
This should not be complicated so I can’t help but think that I am missing something. What it sounds like you need is
get_post_meta
.Edit:
You need a
meta_query
for the most WordPress-y solution:However, your code is easily adaptable:
Note: use
$wpdb
. It will save you some effort.