Considering your current code I think you missed the WP Meta Query class which can do what you want;
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
- WP_Query: include custom post type only with 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
- Multiple orderby values in WP_Query
- 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
- meta_query for keys that aren’t yet set
- how to filter by last name for custom post
- Filtering a WP Query result
- 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?
- 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?
- WP Query group/order by category name
- query order by date on custom type: wrong order
- exclude custom post type by meta key in wp_query
- Having trouble with custom date field for CPT query (WordPress)
- Display posts if a custom field value is equal to another custom field value
- WP Query—Relationship between two custom post types and their fields
- How to dynamically attach pictures to a carousel
- Is it possible to apply a meta_query to one specific post type in a query with multilple post types?
- 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
- Problem querying Custom post type by custom fields
- WP_Query order by custom field, then randomly order some of results
- How to do WP_Query with two meta fields with orderby clause
- Meta Query Not Returning Output Despite Having Matching Values
- Query Multiple Custom Posts by Custom Fields
- Why is this query not working? (Standard posts + custom post type)
- Get Posts by multiple custom fields is not working
- Order Custom Post Type by Custom Field Value
- First custom field value (out of several) displayed twice after query
- Meta Query posts not showing on ending date of custom field
- Configuring a meta query with multiple post types that have the same relationship on a single page
- filter search custom field query
- post_per_page ignored in WP_Query
- WP_query – Filter by tax_query and meta_query using multiple select
- find custom post type post by searching its custom field with my string
- Display custom post type for specific user
- Group by custom field value (start and end times)
- WP_Meta_Query object with conditionals
- Using WP meta query to show custom post types by a start and finish date
- Two queries – one with checkbox ticked, one without – comparing meta_query
- How do I list a custom field and custom taxonomies for each result in a loop?
- 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?
- order the meta query results by 2 custom fields
- WP Query from two Custom Post type fields as statement
- Query custom post type that has a serialized relational advanced custom field value
- Using OR relation in meta_query to check for a value before sorting by another
- WP Admin Dropdown List Filter for custom (ACF) field on custom post type(s)
- WP_Query get always custom post_type for first
- build child and anchestor three from post parent
- How can I query and sort custom-post type using WP_Query
- Custom query result empty on page 2
- Meta query and compare “!=” not working as expected
- Show posts from WP Custom Post Type selected from a field in a metabox
- Query custom post type and custom field by URL parameters
- 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
- Not able to get my custom search result using meta_query and tax_query together?
- WordPress query in which condition uses custom field
- Error in WP Query. If variable is empty it is displaying previous post value
- Querying, storing, and using data from 2 separate custom post types
- Custom Query With Multiple Meta Key Value
- WP_Query get posts where post_name is empty
- Query recent posts by author
- loop through custom post-type with two meta_keys
- Filter Custom post type by another Custom post type
- Get Posts ordered by a date custom meta field
- Order Wp Query by earliest of 3 dates meta query
- Function to Compare CPT Post Custom Value with Default Posts CF Value
- Display ACF object field data using Elementor Custom Query
- WordPress custom field sorting, weird behavior: the latest post is at the end
- Sort CPT by taxonomy AND THEN by custom field
- WP Query + custom fields: How to query event posts from the current date backwards 6 months and organize it month by month?