If the key-2
is uniquely assigned to cpt-3
post type, then you can add another meta query argument to your query arguments:
array(
'key' => 'key-2',
'value' => 1,
'compare' => '='
)
If not, you can run another query, and then merge them as follows:
$final_query = array_merge( (array) $query_1, (array) $query_2 );
But, you should use get_posts()
instead of WP_Query()
since you can’t merge objects with methods. The get_posts()
returns an array of posts which can be merged.
However you should notice, meta queries are expensive and will slow down your website ( probably ).
Related Posts:
- WP_Query orderby custom field then post_date in one query
- Filtering a WP_Query meta_query by numeric values isn’t working
- Comparing timestamps in meta query doesn’t work
- Display two post types ordered by two custom fields
- Filtering by Post Meta Custom Fields – Performance
- Returning a list of custom post types excluding those without a specific meta_value
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- wp_query check if integer exists in custom field’s array
- Possible to filter custom post type with multiple meta data?
- Query based on custom fields start and end date
- Getting a custom post’s custom field based on another custom post’s custom field select
- meta query multiple values for the same key
- Sort custom post archives by a meta value from a different custom post type?
- Custom post types – meta_query: search lesson which starts sooner
- Meta_Query refuses to return results
- Query events post type after current date and timezone
- Selecting posts older than the current Unix epoch timestamp
- Querying meta values within an array
- Custom Post Type + Custom Meta Query Not Showing 2012 Posts
- Using meta_query, how can i filter by a custom field and order by another one?
- Mixing regular and custom post types (with meta_query) on home page
- WP_Query() show posts that end later than today
- how to filter by last name for custom post
- Sorting a query by custom field date
- How can I generate a RSS feed based on a custom WP_Query?
- Querying custom post type with 2 custom fields (date-range)
- Display Custom Post Type Fields
- How Can I save multiple records in same meta key?
- Search Custom Post Type with all meta attached?
- How to sort CPT by custom meta value (date), and return posts month by month
- Using Query Posts With Multiple Post Types And A Taxonomy
- Using new WP_Query in shortcode in a custom field causes the main post content to not display
- WordPress query by multiple Custom fields and order by date
- Can’t sort order of wp_query with 2 meta keys
- Get post info inside modal window?
- query order by date on custom type: wrong order
- How loop through posts based on custom fields
- Having trouble with custom date field for CPT query (WordPress)
- Display posts if a custom field value is equal to another custom field value
- Filter posts with meta_query NOT IN where value has multiple values
- Sort by two dates. Default entry date and custom field if present
- Conditional to modify query results
- WP Query—Relationship between two custom post types and their fields
- Get all Posts If has same custom field values in Posts
- Custom Post type and Custom Field WP_Query
- Setting proper query for multiple custom admin filters
- WP_Query orderby modified to include custom meta changes
- WordPress custom loop filter by meta_key and value with serialize data
- WP_Query order by custom field, then randomly order some of results
- A method for ordering mixed dates in search result loop (theory only, no actual code)
- How to do WP_Query with two meta fields with orderby clause
- Stuck in Order by more then one
- Meta Query Not Returning Output Despite Having Matching Values
- Meta Query Filtering not working on Custom Meta Box using Radio Buttons
- Why is this query not working? (Standard posts + custom post type)
- Get Posts by multiple custom fields is not working
- First custom field value (out of several) displayed twice after query
- Admin Custom Meta Box – Pull Last 5 Posts from Custom Post Type
- How to Output which matched meta_keys were found from custom_type_posts?
- filter search custom field query
- How to let users choose where to search for posts?
- DIsplaying URL of custom field in last post of certain taxonomy && post type
- Display post from a date range from custom field
- post_per_page ignored in WP_Query
- WP_query – Filter by tax_query and meta_query using multiple select
- WP_Query orderby not work with meta_key
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- Display custom post type for specific user
- Custom Post type loop with ACF not displaying properly
- Group by custom field value (start and end times)
- Query Posts, order by meta value
- WP_Meta_Query object with conditionals
- Two queries – one with checkbox ticked, one without – comparing meta_query
- WP query_posts group by meta field related
- How to order query results based on if a custom field has been populated, then the order by the date of the post?
- Custom Form / Search with Custom Post Type Data
- Create if else for post types in WP_Query ‘post__in’ values
- WP Query from two Custom Post type fields as statement
- Using OR relation in meta_query to check for a value before sorting by another
- WP_Query get always custom post_type for first
- Orderby if between two meta fields
- Show posts from WP Custom Post Type selected from a field in a metabox
- How can I fetch all the dates from custom fields from various different custom post types and show / list them at one place in ascending order?
- post type => ‘any’ not applied my custom queries
- How to get the posts that my following users are liked?
- Sort loop by custom field from different post type
- Meta_query by date for Events archive
- Calling specific page with wp query
- WP_Query get posts where post_name is empty
- Trying to combine multiple WordPress queries
- Query recent posts by author
- 404 on Pages for Custom Post Type & Query_Posts
- WP_Query arguments: Loop through custom post type – get all entries except excluded meta_key?
- Filter Custom post type by another Custom post type
- Show Posts in Vertical Tabs with Scrollbar
- Check for custom field value in different post type than current one and do something
- Order Wp Query by earliest of 3 dates meta query
- Display ACF object field data using Elementor Custom Query
- WordPress custom field sorting, weird behavior: the latest post is at the end
- WP Query + custom fields: How to query event posts from the current date backwards 6 months and organize it month by month?