I'm building a phone numbers directory website. Using wp_insert_post()
visitors are allowed to add phone numbers without having to register or log in.
There's a custom post type called "numbers" and phone numbers are stored in custom posts' meta values. Here's the code:
$post_id = wp_insert_post(array (
'post_type' => 'numbers',
'post_title' => $name,
'post_content' => $details,
'post_status' => 'draft',
'tax_input' => $custom_tax,
));
if ($post_id) {
// insert post meta
add_post_meta($post_id, 'number', $number);
}
I don't want my users to add the numbers that have already been added before. I need to somehow check if the entered phone number already exists in any post's meta value or not.
If number already exists in database, user shouldn't be allowed to add it.