0

I have pages that I would like to exclude in a ACF relationship field.

My field name is products and the following code excludes the pages with id 9, 10 or 11.

add_filter('acf/fields/relationship/query/name=products', 'exclude_id', 10, 3);

function exclude_id ( $args, $field, $post ) {

    $args['post__not_in'] = array( $post, 9, 10, 11 );

    return $args;
}

Instead I would like to exclude pages not created by a certain user.

I have user called collaborator and want to exclude all pages that dosen't have collaborator set as author.

I would rather exclude pages by author name rather than the author id, like

author_name('collaborator');

Is this possible?

1

If you want to exclude ALL pages that doese't have 'collaborator' set as author, then you want to exclude all other pages in the site and include all pages of that author minus, maybe, some hand picked pages of that author, then I think you can use this:

add_filter('acf/fields/relationship/query/name=products', 'exclude_id', 10, 3);

function exclude_id ( $args, $post ) { //$field input vriable wasn't neccessary in this function

   $args['post__not_in'] = array( $post, 9, 10, 11 );
   $args['author_name'] = 'collaborator'; // Queries only the collbaroator's posts

   return $args;
}
|improve this answer|||||
  • Worked perfectly. – Liu Kang May 9 '15 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.