How to remove registered custom post types from custom Fields list?

Asked

Viewed 70 times

1

Good night! I created some custom post types through the register_post_type command in wordpress, along with custom Fields (post meta). The problem is that they appear along with the custom Fields in editing the pages (menu pages), as I do to remove them from there?

I would like only custom Fields of each page to appear in page editing and not the fields I created for post type.

2 answers

2

Without seeing the code that creates the meta-boxes we just have to kick.

Probably somewhere in your code there’s a call to add_meta_box() where the fourth parameter - $screen - is empty, false or has not been passed. If you put the post_type name it will appear only on the screens of that type.

  • Follows the code:

  • ... register_post_type( 'banners' , $args ); } /** BANNER REGISTRATION */ add_action("admin_init", "startBanners"); Function iniciaBanners(){ add_meta_box("Z_ordembanner", "Banner Appearance Order", "Z_ordembanner", "banners", "normal", "low"); }

  • i put the post type "banners" to appear only on that type of post type... but it is appearing on the custom Fields of all pages...

  • hm, it might not be that, but I saw that you’re calling add_meta_box within the action admin_init. The correct action is add_meta_boxes, Strange things happen if you hook up too soon.

2

So that your Custom Fields do not appear in the list of a post/page/CPT, have to use a underscore at the beginning of the name.

For example, this appears on the list: meu_custom_field. This nay appears: _meu_custom_field.

  • 1

    Perfect! This solution solved my problem!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.