Home › Forums › General Issues › Relationship field: seems like altering the query doesn't work › Reply To: Relationship field: seems like altering the query doesn't work
I tried the example from the docs and it seems to be working as expected
function my_relationship_query( $args, $field, $post_id ) {
// only show children of the current post being edited
$args['post_parent'] = $post_id;
// return
return $args;
}
// filter for every field
add_filter('acf/fields/relationship/query/name=relationship_query_test', 'my_relationship_query', 10, 3);
If you are still having trouble with this then try deactivating other plugins and/or switching to an unmodified 20XX theme to see if there is still a problem. Something else could be interfering with the query.
As far as altering the query to get pages that use a specific template, you will have problems with this due to the way ACF sorts the post when the post type is hierarchical. Basically, in this case it really can’t be done. ACF attempts to order the posts in hierarchical order and if the parent of a page is not returned because of the filter then the results will be incorrect. So, the ability to filter the query can be limited on hierarchical post types.
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.