WordPress.org

Make WordPress Core

Opened 3 months ago

Closed 3 months ago

Last modified 3 months ago

#54007 closed defect (bug) (invalid)

Custom Post Type, missing meta boxes in edit screen (featured image, custom taxonomy)

Reported by: geertvanderheide Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.8
Component: General Keywords: close
Focuses: Cc:

Description

I've added a CPT using register_post_type() inside a simple plugin. As expected, the new post type shows up in the Admin menu with the correct labels and icon. For the 'supports' argument I've added: array('title', 'excerpt', 'editor', 'thumbnail'). I expected to see these features on the post edit screen, as in WP 5.7 and before. But instead of the Featured Image meta box, I only get an empty div in the Block Editor's sidebar, with class "components-panelbody".

I can go into the Block Editor's preferences and then to "Panels", where there are toggles for each panel. The Featured Image toggle does show up there. Toggling this block only shows or hides a single border (1px) in the sidebar, so it's showing and hiding the empty div, but nothing else.

I've attached an example image, as well as the code used to register the post type.

Meta boxes like the Excerpt do work as expected for this CPT, and so does the 'page-attributes' block if I add that to 'supports' and set the CPT to 'hierarchical'. The featured image also does work for default post types, just not for CPTs.

The featured image meta box is also missing in the Classic Editor - there I can't toggle anything though - it doesn't show up under Screen Options with this Editor.

Related: I also added a custom taxonomy and it doesn't show up as a meta box for the post type either. Strangely I can set taxonomy terms from the Quick Edit feature on the CPT's admin list and they are shown, and values are saved. Yet there's nothing on the post edit screen. No toggle for it either.

There are no PHP errors shown, and no JS errors in the console at all. I've triple checked my Block Editor setup and I'm not doing anything related to these features at all.

I've added add_theme_support('post-thumbnails') inside 'after_theme_setup' in functions.php - this always used to apply right away to any post type I would add. Now it doesn't.

'show_in_rest' is set to true for the post type.

What I've tried:

  • Using a default theme with no active plugins (other than the one registering the CPT + Custom Taxonomy). Problem still occurs.
  • Using Health Check to activate / deactive different things. Nothing seems to help. Checked the integrity of the files - nothing wrong there.
  • Triple checked my code used to register the post type and taxonomy. It's the same as the documentation. The CPT and the Custom Taxonomy are also correctly linked, through the CPT's 'taxonomies' argument and in the function call for register_taxonomy().
  • Re-installed WordPress 5.8 entirely. No change.

Similar reports talked about several possible causes and I've ruled them all out, mostly by trying the default TwentyTwentyOne theme:

  1. The spelling of the theme folder could be related if it has a name containing only 4 numbers. My theme name does not have that issue, as it is simply named "Main".
  1. Some issues with custom capabilities may cause behavior like this, but I'm only using default capabilities ('post' or 'page') for the post type. I'm using WP as an administrator user.
  1. Issues related to child themes have led to missing meta boxes apparently, but I'm not using a child theme, only a main custom theme, or a default theme.
  1. Issues relating to the theme header inside style.css have been reported as causing missing panels, but I've triple checked mine and nothing's wrong.
  1. Themes with either no style.css, or no index.php file may have this issue apparently. I've checked that both are present, with no errors.

Attachments (2)

example.png (8.3 KB) - added by geertvanderheide 3 months ago.
Example image of the missing block
register_post_type.php (4.3 KB) - added by geertvanderheide 3 months ago.
Code used to register the post type and taxonomy

Download all attachments as: .zip

Change History (5)

@geertvanderheide
3 months ago

Example image of the missing block

@geertvanderheide
3 months ago

Code used to register the post type and taxonomy

#1 @karpstrucking
3 months ago

  • Keywords close added

@geertvanderheide I believe this is because you're defining empty values for the thumbnail labels:

    'featured_image'        => '',
    'set_featured_image'    => '',
    'remove_featured_image' => '',
    'use_featured_image'    => '',

If you define these or remove them this should solve your issue.

#2 @geertvanderheide
3 months ago

  • Resolution set to invalid
  • Status changed from new to closed

@karpstrucking Thank you for checking what was wrong! Your suggestion helped - the Featured Image shows up now. And the missing taxonomy meta box was also because of a small error on my part: I forgot the 'show_in_rest' parameter there.

I apologize for making this a bug report - I should have asked for support on the WP forum. Ticket may be closed.

#3 @desrosj
3 months ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.