Skip to content

Instantly share code, notes, and snippets.

@mager19
Created December 20, 2022 20:21
Show Gist options
  • Save mager19/6f5b977e8dcc1a340729e19ea54ac4a9 to your computer and use it in GitHub Desktop.
Save mager19/6f5b977e8dcc1a340729e19ea54ac4a9 to your computer and use it in GitHub Desktop.
Reverse query relationship acf field
//obtain pages or post who added a relationship item - Reverse relationship posts
$tasks = get_posts(array(
'post_type' => 'task',
'meta_query' => array(
array(
'key' => 'task_parents', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment