It doesn’t seem possible to create a Meta Query in the Query Loop when comparing a relationship or post object field against the post title of the active item?
In the screenshot I have created 2 fields and 2 Meta Queries. The Query relating to the Service Text field works as expected, however the query relating to the Service Post Object field doesn’;t return a value.
Not raised as a bug as it may be an ACF issue but can’t find a workaround
Ran into this a few days ago and did it like this:
add_filter( 'bricks/posts/query_vars', function( $query_vars, $settings, $element_id ) {
// Use an ACF custom field to restrict the query to a set of posts
if ( $element_id == 'knmaqa' && function_exists('get_field') ) {
$query_vars['post__not_in'] = get_field('relevante_rechtsgebiete');
}
return $query_vars;
}, 10, 3 );
knmaqa is the ID of the loop and relevante_rechtsgebiete is the acf relationship field
In my case, I needed to get all the posts that aren’t in the relationship field. If you wanna loop and show all posts from a relationship field though, you can just select it straight in the query builder
Hi Martin - great tip I’ll give this a go. I had found a messier function that basically copies the postid content of the ACF object field into an ACF text field. It works but not the cleanest solution
I don’t know if you’ve already found a reasonable fix for your problem, given this thread is pretty dated. But I just ran into the same problem with filtering by an ACF Relationship/Post Object.
I found that by checking against {post_id} instead of {post_title} in the Meta Query gave me a successfull output