Couple of things to consider here:
1.) Try adding the meta query only if the value is present:
$pairedThing = get_field('myThing');
$args = [
'posts_per_page' => 2,
'post_type' => 'thing',
];
if ( ! empty( $pairedThing ) ) {
$args['meta_key'] = 'identifier';
$args['meta_value'] = $pairedThing;
}
2.) Account for posts without the meta-key set:
$pairedThing = get_field('myThing');
$args = [
'posts_per_page' => 2,
'post_type' => 'thing',
'meta_query' => [
'my_meta_query' [ // Multiple meta-queries per handle.
'relation' => 'OR',
[
'key' => 'identifier',
'value' => $pairedThing,
'compare' => '=',
],
[
'key' => 'identifier',
'compare' => 'NOT EXISTS',
],
],
]
];
Related Posts:
- Using OR conditions in meta_query for query_posts argument
- Revolution Slider Orderby Two Custom Fields
- wordpress ajax relationship query
- Include post content of linked posts in search
- filter wp_query result with custom field values
- ACF: How to query for a given value count of an array like field? (e.g.: How many rows has a `flexible_content` field?)
- WP Query – grouping posts by same meta key, adding together values from another key
- WP_Query, ACF field and array
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- Wrap group of wp query posts to parent div by date/year
- Query posts filter not working
- Display all custom meta field values from the database using ACF Repeater
- Best performance for use Custom Field in WP
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Conditional operator OR not working with custom fields
- Merge 2 custom post type posts and taxonomy terms and sort ascending
- Add ACF field in a query
- Getting rid of unwanted nonSQL syntax characters when debugging a query
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- JSON – Create rest api endpoint for Advanced Custom Fields
- WP ForLoop to compare meta information of posts to determine what post to display
- WP_QUERY with group by with custom fields
- Query where ANDing slug values not working
- How to order posts on each different category?
- Intiger meta value with ‘>=’ returns posts with lower value
- Display posts with specific value first in query
- get_posts custom field
- Get every post with value in meta key
- Using get_posts to get posts based on a checkbox value with Advanced Custom Fields
- wp_query posts with custom fields number smaller than
- Slow Query On Search
- Posts query according to meta box date
- create metabox to activate slider
- WP_Query: apply an SQL function to meta fileld value
- Query posts using less than
- Expecting statement error from php loop using ACF plugin
- 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
- Custom query filter by ACF date custom field
- Order WP_Query results by meta key value in custom query
- Excluding posts with certain value of meta_key keeping posts without that meta_key
- Query only displays one page_id
- Group by custom field value (start and end times)
- Get a list of ACF Repeater-Fields as array
- Querying a large number of posts including their custom fields data
- Display post meta conditionally based on it’s value
- Query using string from custom field as array value
- WP_Query custom field pass the post id
- How to show list of posts with custom field value (a date) that are coming soon
- add_query_arg to compare and display events from a certain date
- WordPress dynamic AJAX query
- Comparing 2 Decimal Numbers from custom fields and displaying posts
- Sorting posts by Multiple custom fields in defined order
- How to avoid filling up an array each time I run a WP_query?
- How to SQL query posts IDs by categories AND authors?
- Randomly select one of last 3 posts
- WP Query orderby ACF boolean values and ACF field value
- Optimising WP_Query with ACF Fields
- meta_query weird behaviour, static int will work, but not user data
- Query multiple post types, but different order for each
- Order by the first array within a meta_query
- Order WP_Query by meta_key priority when ‘OR’ relation used for multiple meta values
- Woocommerce Shortcode which displays a table with product data
- Query ACF relationship field – Comparator IN – Value array
- Multi-layered WP_Query
- Oxygen Repeater Advanced Query
- SQL query injection with fifu image
- Nearby locations using Advanced custom fields, maps?
- WP_Query – display posts by custom field and order by another
- WP_Query for distinct meta values
- Group Product Types
- Passing a SQL query to the WP Query
- How to _GET multiple value checkbox WP_Query in Custom Toxonomy / Custom Fields
- Create if else for post types in WP_Query ‘post__in’ values
- 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?
- Sort custom post by custom field if none order by latest release
- WPQuery Date and ACF
- display ACF repater field in archive page
- WP_Query() not working as expected
- Excluding posts from search results page with meta query not working
- Query posts by post type, author and post meta
- Populate select list with meta values from all posts of a Custom Post Type
- Form checkbox value going to dynamic URL
- How to use the Term Object from a custom select field in a query
- Retrieve all custom field values of a specific custom field metakey as an array, inside WP_Query
- ACF: How can I publish values of ACF fields in a loop while using wp_query?
- meta_query is overriding default search
- Any way to use FETCH_KEY_PAIR with $wpdb?
- Trouble with serialized metadata
- Categories In English version showing not canonical URL, instead shows query search result
- Query on a repeater date (acf)
- WP Query by variable custom field
- What is the equivalent WP_Query of a SQL Query?
- create custom shortcode wp and put php code in
- Query for getting posts with their custom fields data in WordPress
- Comparing Meta Field date in WPQuery using Meta_Query?
- Filter posts by their related field’s custom field
- Why does my output of get_the_ID() change after a wp_query?
- Getting posts by custom field value