Check the Codex. meta_query
accepts an EXISTS
comparison.
$args = array(
'post_type' => 'somepostype',
'meta_query' => array(
array(
'key' => 'fname'.$userid,
'compare' => 'EXISTS',
),
array(
'key' => 'lname'.$userid,
'compare' => 'EXISTS',
)
)
);
$query = new WP_Query( $args );
return $tempquery->found_posts;
There is a note that…
Note: Due to bug #23268, value is required for
NOT EXISTS
comparisons
to work correctly. You must supply some string for the value parameter
– Note: empty string or NULL do NOT work. However, any other string will do the trick and will NOT show up in your SQL when usingNOT EXISTS
.
It sounds as though EXISTS
is not effected but I have not tested that. However, you may need to add a placeholder value
if that still doesn’t work.
Related Posts:
- WP Query Args – Title or Meta Value
- Meta query with string starting like pattern
- how to show posts that are missing a meta_value
- Does tax_query really beats meta_query in all situations?
- Query WooCommerce orders where meta data does not exist
- Execute a large WP_Query with many “AND” Meta_Queries?
- Query all posts where meta value is empty
- WP_Query min and max values
- WP_Query using meta_query with relation OR and orderby meta_value doesn’t work
- querying with custom meta field with meta_query
- Order by two meta keys
- multiple meta key but get server load is very high
- A WP_Query that will look for posts after 2 weeks ago OR with a certain meta value
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- Use meta_query to display events by date in custom field
- Meta-value query
- Meta query field order together with post_date order causes posts without the meta field to be unordered
- How to show recent and upcoming birthdays using meta_query
- pre_get_posts filter meta_query without conflicting existing meta_query
- Undefined property: WP_Query::$post
- Programmatically set ‘meta_query’ for filter
- Using WP_Query and WP_Meta_Query Outside of WordPress
- If two first numbers exist in wp_meta_query value
- WP_Query meta_query >= date
- Extending woocommerce admin product search
- WP_Query on custom field and order results
- Complex Orderby Parameters: How to query with multiple orderby parameters using meta_value_num?
- Tax query clause inside a meta query clause?
- Adding an array from a query string to a WP meta_query
- Query multiple meta values
- Optional Meta Query
- Query by multiple meta elements not seeming to work – wordpress is timing out
- How do I make a meta_query OR relation work? [closed]
- Meta_query on same meta key, with diffrenct values
- Can we return all category (not post) with Custom Query Filter? [closed]
- Extend product search with meta in WooCommerce
- How does one perform a sub query with different post types
- how to make members list directory through wordpress post custom meta key.
- WP_Query with meta_query dosen’t return results
- meta_compare not comparing whole integer
- How to provide meta_key array to wp_query?
- meta queries do ‘either/or’ checks
- How to set up hierarchical relationships without using plugins / meta query
- WP Query ordering on a meta field for posts with a date in the future not ordering by datetime
- Selecting posts with a given meta value for a meta key
- Meta query compare for ID’s greater than specific ID
- Get every post with value in meta key
- get_page meta query not working, maybe a bug?
- Is it possible to add relation between meta_query and tax_query?
- Query by date from custom field
- Is it possible to retrieve posts depending on meta_key LIKE condition? [duplicate]
- Show single posts date, in a page of posts
- Comparing 2 Decimal Numbers from custom fields and displaying posts
- WP_Query Class custom field parameters
- Sort posts using multiple custom fields and menu_order in single query?
- meta_query where the meta value is not the post title
- Order WP_Query by meta_key priority when ‘OR’ relation used for multiple meta values
- Order (by ASC) posts with meta_key so posts without values are last
- Search filter between promo and exact price
- meta_query with meta values as serialize arrays
- Woocommerce Get Orders By Meta Value
- meta_query is overriding default search
- Multiple WP_Query args combinations according to post type
- WordPress Meta Query Null Values Order
- WP_Query multiple value not working
- show most viewed post
- WP_User_Query Orderby Not Working
- Why can my filter query SOME metadata but not other metadata?
- Getting posts by custom field value
- Unusual high query of user meta data
- WordPress Query optimaization for slow query
- wordpress multiple meta value query is not working
- Strange results from WP_Query
- Pre get posts sort by meta key returns no results if meta key does not exist
- meta_query with relation = AND not working as expected when combining EQUALS with NOT EQUALS
- WP Query for Multiple Post Types
- Meta query doesn’t remove placeholder escape before query
- Order Posts By Custom Field That is an array of objects
- WP Query Meta Query
- Orderby query does not work for custom fields even with meta query
- Query custom meta value – post view and date meta
- How can I modify standard search query to include also ACF custom fields values?
- make query more simplest and in one query
- Custom WP_query and integrating into theme file
- WP_Query – show posts where meta value and user_email match
- Best way to Order Post in Home without a plugin
- WP_Query using meta_query with LIKE doesn’t return what it should
- Use not custom fields in get_posts() meta_query?
- Compare meta key separation
- Return a single custom post from multiple meta queries
- query post based on comparison
- WordPress Query Default Order if Meta Values Same?
- Including ‘cat’ => $cat breaks meta_query
- Custom query (author is post_author or meta co_author) with Pagenavi pagination
- Query string form $_GET[‘value’] is not working as meta value in wp_query
- 294 Queries on Mainpage of WordPress
- How to get all post_id and meta_value using meta_key in wp_postmeta table
- WP Query – Show custom posts only if user contain some user meta
- How do I subquery with custom meta fields?
- Showing Counts on Comment List with Custom Query