I don’t think there is a built in mechanism for searching the meta table for a key
/value
pair other than a full blown post search with WP_Query
. I’d consider that overkill. Just query the table:
$unique = $wpdb->get_var(
"SELECT meta_id
FROM {$wpdb->postmeta}
WHERE meta_key = 'unique_code'
AND meta_value="{$random}"
LIMIT 1"
);
I can’t help but think that more detail in the question might point to a better way to proceed
Related Posts:
- Meta Query with AND & OR?
- Upcoming Event: How do I sort database by custom date field, but ignore past dates?
- Conditional custom field query
- Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months
- How to query for posts with either one or another custom field
- Complex WP_Query Using Post Date And Post Meta
- WP_Query – Order results by meta value
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Filter WP_Query for posts having a certain meta-value
- Can I query custom meta data through WP_Query
- How to rename a custom field?
- How can I make wp-pagenavi work on a custom query built upon a form submission? [closed]
- How do I search an array stored in a custom-field using WP_Query?
- How do I order by multiple custom fields using wp_query?
- Trying to perform complex custom field query with order by set to field value
- Query meta field using between
- Order Posts by Closest Numeric Values
- 2 orderby in wp_query with 2 custom fields
- Can serialized arrays in DB be matched against serialized arrays with meta_query?
- How to get a meta value from all post
- Compare meta_query decimals not working right
- WP_Query multiple use of relation and/or
- Query Problem – Show posts within category ‘x’ that have a custom field between ‘y’ and ‘z’
- Comparing timestamps in meta query doesn’t work
- Display two post types ordered by two custom fields
- Using OR in WP_Query negates the “NOT EXISTS” compare
- WP_query : meta_key with custom rule for specific value
- How can I combine meta_query queries?
- How to filter a dd/mm/yyyy date from a custom field in a query
- Having trouble with custom date field for CPT query (WordPress)
- Using WP Query to search by multiple meta fields
- Difference between ‘LIKE’ and ‘IN’ in meta queries
- Plugin similar to Taxonomy Drill-Down for custom fields?
- Compare WP Custom Field date
- Sort by posts that have a featured image?
- WP_Query display next custom post from today’s date
- Order by value in serialized custom field
- $wp_query meta_key naming issue [closed]
- Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
- How do I query for a post by custom field?
- Meta_query and numeric comparison [closed]
- Conditional to modify query results
- Count how many posts have a custom field set
- Adding Custom Fields to Search
- Any way to include custom fields in WP_Query results?
- sort search results by custom fields using dropdown
- Multiple relationships in a query
- How can I sort homepage by a meta value?
- Loop to display random posts only if a custom field matches category
- WP Query Returning All Posts
- How do I use wp_query for WordPress search?
- Meta query with timestamp using WP_query
- Order query by meta_value with multiple custom fields
- Display only past events on that page using Visual Composer Grid Bulider
- Add quicklink to in the Admin posts page where I can query by a meta_key
- Custom Field Create Bulk via SQL Query
- Create Pop-Up Box with Custom Field Content Inside the Loop
- Auto Populate Custom Field with Complex Value That Increase by One?
- query usermeta from custom field
- Is there any way to get all meta and standard columns for any WordPress object after searching based on meta key and value
- Order RSS content by an advanced custom field value
- Order by empty custom field
- Alter main archive, to show posts with meta as last
- First custom field value (out of several) displayed twice after query
- Custom WP_Query for WordPress Search Results with meta_query
- Meta Query And/Or
- How to combine custom fields to make one order-able value
- Trying to reorder posts by custom field
- Limits, not all post are showen when querying for posts by view count
- Why orderbyb meta_value_num won’t affect the generated SQL Query order?
- Get post ids sorted by meta_key
- querying a custom field
- Passing meta_box string to post__in?
- pre_get_posts : only get posts by wp_usermeta value
- meta_value and meta_key filtering returning no posts [closed]
- Select custom posts by meta_value and sort by a different meta value
- Can’t query by meta_key
- Adding custom field and querying from post table
- How to query an out put value?
- List custom queried terms in the edit-tags.php?taxonomy page
- Modify date query by URL parameter using pre_get_posts and $_GET
- Loop through incrementing custom fields
- Custom search SQL Query to add custom field in result
- Meta query relation ‘OR’ not working as expected
- WP_query multiple custom fields not working
- How to exclude custom fields from search queries?
- WP_Query () using taxonomy, custom post types
- Custom Query Fields – Altering Meta Value
- Multiple Custom Field Query
- Best way to sort estates and query them (for rent? yes/no. contains office space? yes/no)?
- Custom Query: query by post custom meta data
- Get array of posts based on custom field values
- How to update custom field of a posts in a particular category
- Searching with Multiple (Parallel) Criteria on Custom Fields?
- How to query posts by month based on date custom field?
- How can I modify my meta_query to work with prices that are stored in the database that contain dollar signs and commas?
- Custom Field Date Problem
- Query multiple post types, but different order for each
- Compare ACF date field (if exists) and post date and order DESC
- Problem with revisions only returning four results