0

I am trying to implement custom post type in Wordpress.

plugin: Advanced Custom Fields

    register_post_type('acf', array(
        'labels' => $labels,
        'public' => false,
        'show_ui' => true,
        '_builtin' =>  false,
        'capability_type' => 'page',
        'hierarchical' => true,
        'rewrite' => false,
        'query_var' => "acf",
        'supports' => array(
            'title',
        ),
        'show_in_menu'  => false,
    ));

However, my another plugin, which displays only user's content (posts, pages, media...) is disabling also the metaboxes created by this plugin.

This is the code of the small plugin which displays user's stuff (thanks goes to another post and person)

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');

Users now can't see metaboxes which I created as admin on the website.

0

You need to include the post type in the pre_get_post filter:

(Not sure about global $user_ID;, just reproduce that part of your code)

function content_for_current_author($query) {

    if($query->is_admin) {
        global $user_ID;
        $query->set('author',  $user_ID);
        $query->set( 'post_type', array('acf', 'another-custom-pot', 'page', 'post') );
    }
    return $query;
}
add_filter('pre_get_posts', 'content_for_current_author');

Details in WP Query documentation for Type Parameter

Also, your custom post type dosn't support custom fields, maybe that is hte reason of meta boxes don't showing. Not sure here because I don't know how ACF works. Try to add support for custom fileds to your post type; change the support argument to:

supports' => array(
            'title',
            'custom-fields'
        ),
4
  • No luck, and with this added, even media files aren't displayed anymore. And main thing, meta-boxes created by Advanced Custom Fields ('acf' post type) didn't appear. Wouldn't it be possible to force this post type to display to all users?
    – JNV
    Sep 13 '14 at 13:43
  • or what about giving exception into the code above?
    – JNV
    Sep 13 '14 at 13:46
  • Obviously, if you copy and paste the code I posted, attachments are not included because attachemnt post type is not set in the post_type argument of the query. You must include every type os post you want in the $query->set('post_type') or set to any to include all. See details in WP Query documentation for Type Parameter. About your issue with meta boxes created by ACF plugin, you should ask in ACF forums. Instead, if you are coding the meta boxes show us the code you are trying and we will help you.
    – cybmeta
    Sep 13 '14 at 15:19
  • Understand. I created these meta-boxes through ACF. I have already wrote them =) (Yep, I could probably do that as first thing). It'll be maybe easier than it seems.
    – JNV
    Sep 13 '14 at 17:55

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.