Support

Account

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 🙂