Support

Account

Home Forums Backend Issues (wp-admin) Meta Boxes missing

Solving

Meta Boxes missing

  • I am like hitting my head to the wall whole day.
    I have 2 meta boxes created by Advanced Custom Fields.

    However, I also have this code, which displays only user’s stuff (only own content, posts, pages etc.)

    function content_for_current_author($query) {
        if($query->is_admin) {
            global $user_ID;
            $query->set('author', $user_ID);
        }
        return $query;
    }
    add_filter('pre_get_posts', 'content_for_current_author');

    This code is working perfectly.

    But it also disables those 2 meta boxes from ACF.

    Can you guys please help me?

    It would be awesome to finally solve it.

  • I have exactly the same issue. Would be most appreciated if a solution would be provided.

    Cheers!

  • I think I got this solved.

    I have created the fields with the Admin user (user_id == 1) and the field appeared when I modified the query to include the Admin user_id. Here is the code I’m using now to prevent other users from seeing others posts and displays the fields on post.php page.

    
    add_filter('pre_get_posts', function($query) {
    
        if ($query->is_admin) {
            global $user_ID;
            global $pagenow;
    
            $allowedPages = ['post.php', 'post-new.php', 'admin-ajax.php'];
    
            if (in_array($pagenow, $allowedPages)) {
                $query->set('author__in', [$user_ID, 1]);
            } else {
                $query->set('author', $user_ID);
            }
        }
    
        return $query;
    
    });
    
    
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Meta Boxes missing’ is closed to new replies.