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
Ah, I found my mistake. I did what you said, disabled the plugins and changed the theme. That worked out.
When I tried to changed it back to the theme we’re using, and put the code in functions.php, earlier it was in another file, it worked.
Then I put it in the original file which gets included in the functions.php file, and it stopped working. Then, I noticed I forgot to add the namespace before the callback.
So this works:
function my_relationship_query( $args, $field, $post_id ) {
// only show children of the current post being edited
$args['post_parent'] = 7;
// return
return $args;
}
// filter for every field
add_filter('acf/fields/relationship/query/name=_theme', __NAMESPACE__ . '\my_relationship_query', 10, 3);
I’ll change the id of the post to a field which they can set on an options page.
Sorry about that, and super thanks for your help!
Hope I didn’t take to much of your time 🙂
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.