Home Forums General Issues Relationship Query to Filter/Reduce displayed posts


Relationship Query to Filter/Reduce displayed posts

  • I want to use the Relationship Query to reduce the amount of search results for a post type.

    Currently, there are about 4000 posts of ‘artwork’ and each piece of ‘artwork’ relates to an ‘artist’

    When on an individual ‘artist’ page to edit. I’d like to display items in their ‘portfolio’. The ‘portfolio’ is currently the Relationship ACF field but it’s showing all ‘artwork’, which is searching 4000 posts.

    I’d much prefer the relationship field to only show ‘artwork’ which has been associated to the current ‘artist’. The association is an ACF Post Object which returns the ID.

    Here’s the code:

    add_filter('acf/fields/relationship/query/name=selected_artwork', function ($args, $field, $post_id) {
        $args['post_status'] = ['publish'];
        $args['post_type'] = 'artwork';
        $args['meta_key'] = 'creator';
        $args['meta_value'] = $post_id;
        $args['meta_compare'] = '=';
    	return $args;
    }, 10, 3);

    This current filter returns no updates/modifications to results. Any help is appreciated!

Viewing 1 post (of 1 total)

The topic ‘Relationship Query to Filter/Reduce displayed posts’ is closed to new replies.