Home Forums General Issues Custom Fields and pre_get_posts filter


Custom Fields and pre_get_posts filter

  • Hi,

    i’ve a problem with a pre_get_posts filter:

    add_filter(‘pre_get_posts’, ‘posts_for_current_author’);
    function posts_for_current_author($query) {
    global $user_level;
    $user = wp_get_current_user();

    if($user->roles[0] != ‘administrator’) {
    global $user_ID;
    $query->set(‘author’, $user_ID);

    return $query;

    I want show to individual authors only their post, this filter work fine but the user can’t show the custom field (created by administrator user)!

    Can I set that a user can only see posts/pages that has created BUT including all associated custom field?


  • Hi,
    i solved it this way:

    if( isset($query->query_vars[‘post_type’]) && $query->query_vars[‘post_type’] == ‘acf’ ){
    return $query;

    Thanks for your excellent plugin!

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.