Support

Account

Home Forums General Issues filtering relationship problem

Helping

filtering relationship problem

  • I have a relationship field linking PROJECTS with CONTACTS.

    At the moment the relationship shows ALL contacts available to each project, but I’d like only contacts which the user has put in.

    The example used on this site is this:

    add_filter('acf/fields/relationship/query/key=field_5e94a61df90dd', 'projects_relationship_query', 10, 3);
    function projects_relationship_query( $args, $field, $post_id ) {
    	
        // only show children of the current post being edited
        $args['post_parent'] = $post_id;	
        return $args;
    
    }

    This works fine. But when I substitute the following line it does not and simply shows ALL the contacts, no matter who the author of the post is.

    $args['post_author'] = get_current_user_id();

    Am I missing something obvoous here?

  • SOLVED: use ‘author’ instead of ‘post_author’

    $args[‘author’] = get_current_user_id();

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘filtering relationship problem’ is closed to new replies.