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

  • 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.