You could use NOT EXISTS
as the value for comparem, you could also check for empty value if thats relevant
This code only checks if hidden
meta does not exists
$postsForSitemap = get_posts([
'numberposts' => -1,
'orderby' => 'modified',
'post_type' => ['post', 'page'],
'order' => 'DESC',
'meta_key' => 'hidden',
'meta_compare' => 'NOT EXISTS'
];
This checks is hidden
meta does not exists OR has no value
$postsForSitemap = get_posts([
'numberposts' => -1,
'orderby' => 'modified',
'post_type' => ['post', 'page'],
'order' => 'DESC',
'meta_query' => [
'relation' => 'OR',
[
'key' => 'hidden',
'compare' => 'NOT EXISTS',
],
[
'key' => 'hidden',
'value' => ''
]
]
];
Related Posts:
- Get_post() with meta_key when compare is a date
- get_posts custom field
- Using get_posts to get posts based on a checkbox value with Advanced Custom Fields
- Posts query according to meta box date
- Mathematical operations on custom field values? (updated)
- When to use WP_query(), query_posts() and pre_get_posts
- Meta query with string starting like pattern
- compare meta_query in get_posts arguments
- meta_query: using BETWEEN with floats and/or casting to DECIMAL
- Get Recent Posts by Date in Multisite
- Query all posts where meta value is empty
- meta_query where value is equal to given value
- get_posts not finding argument: post_name
- querying with custom meta field with meta_query
- Group posts by custom field
- Function to check if author has posted within the last x days
- getting posts and number by specific meta value in multiple meta
- How to query using a combination of custom_field values?
- Revolution Slider Orderby Two Custom Fields
- WP Query post meta value
- get_posts() seemingly ignoring post_type
- Can not switch the queried post in pre_get_posts hook
- Count posts returned by get_posts in external PHP script
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- wp_query with multiple custom fields
- SELECT * FROM $wpdb->posts WHERE ID > 160
- Filtering posts by custom field value not working
- Display link to taxonomy archive only if it has posts with certain custom field values
- Adding multiple post queries with parent and children to page – Best Way
- Create a sitemap without a plugin – get parent pages only?
- Creating a custom search for a specific post type
- Group WP_Query by meta_key date
- get_posts – find out if querystring was crap and fallback is used
- How To Fix WP Query Returns Results But Shouldn’t?
- Output an array of terms for a ‘tax_query’ => array()
- Creating query to show which editor (classic or block) was last used to edit a post/page
- Return Taxonomy/Term Information with Posts (WP_Query/get_posts)
- Display custom field meta outside loop, site wide
- Orderby is working with one query but not with other
- add active class based on permalink and url
- Weird orderby => post__in issue
- Extend product search with meta in WooCommerce
- how to make members list directory through wordpress post custom meta key.
- Adding multiple meta_key fields as orderby options to a WP Query via a function
- meta_value_num not ordering all items
- Conflict with get_posts and the_content
- WP Group posts by year(desc) > month(desc) > date(asc)
- How to show more post at a given category?
- Get posts by list of post IDs ordered by those IDs?
- Reset WordPress Post Query to default
- Best choice for multiple loop in page?
- meta_query: check if number exists
- WP_Query Meta_key is text value and need to sort as numeric not working
- filter wp_query result with custom field values
- Order post type by sum of two custom fields
- Use WP_Query or query_posts() or get_posts() for optimizing a site?
- “paged” in WP_Query returns 0 posts
- Specify strict ‘order by’ in WordPress query
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- Check if searched number is within the post meta value
- Retrieve select tag custom values from array and display them in current page with wp_query?
- How to use a dropdown to filter posts by custom field
- WP_User_Query and user posts
- Order WP_Query results by meta key value in custom query
- add_query_arg to compare and display events from a certain date
- Why always one post missing
- Query multiple post types, but different order for each
- How to add date_query to meta_query array
- Order by the first array within a meta_query
- Why my query is not “Main_query”?
- Query ACF relationship field – Comparator IN – Value array
- How to _GET multiple value checkbox WP_Query in Custom Toxonomy / Custom Fields
- Facing problem with tax_query results
- How do i create a custom post query when the meta value is an array?
- How to add a “base” filter for all posts visible to visitors on the site?
- WP Query – grouping posts by same meta key, adding together values from another key
- Retrieve all custom field values of a specific custom field metakey as an array, inside WP_Query
- meta_query is overriding default search
- Comparing Meta Field date in WPQuery using Meta_Query?
- Order 2 meta_queries differently in WP_Query?
- Order posts by title and custom field value?
- How to create URL parameters to run custom queries?
- get_posts query caching?
- Get posts with any value in attribute
- List users by Year of Birth using a foreach loop to dynamically populate years and data
- Slow query when selecting with large meta query or post__in
- Custom WP_query and integrating into theme file
- Sorting posts by meta values: 2 different orders
- Order by three custom fields (Y-m-d), then separate into yearly sections
- Both WP_Query and get_posts returning 1 post
- Loop through multiple custom fields with increasing number
- new WP_query using custom fields
- query post based on comparison
- Weird query with get_posts and WP_Query
- orderby and order filter in get_posts or WP_query function in wordpress not working
- tax_query not working properly with get_posts
- Query custom post types by meta field in a term from custom taxonomy
- WordPress extremely slow when using get_posts with multiple meta_query relations
- WP_Query sort by ACF date field (newest first) with blank dates first
- Sort by multiple columns using get_posts