Home › Forums › Feature Requests › Relationship Field: filter for posts (i.e. image) › Reply To: Relationship Field: filter for posts (i.e. image)
Hi @nicmare,
This is something you can hack using the acf/fields/relationship/query
filter. This filter will allow you to modify the $args array used to query the posts. For instance, should you want to query only posts which have featured image set, then you could use the following code:
add_filter('acf/fields/relationship/query', 'my_relationship_query', 10, 3);
function my_relationship_query( $args, $field, $post ){
$args['meta_query'] = array(
'key' => '_thumbnail_id',
'compare' => 'EXISTS'
);
return $args;
}
For more info on this, have a look at
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
✨ You can now install ACF PRO with Composer, eliminating the need for third-party installers. Get the details and instructions here. https://t.co/ebEfp60Pwj
— Advanced Custom Fields (@wp_acf) February 2, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.