0

In two of my site's custom post types, the topic (in the Topics meta box -- see screenshot below) won't save. This is not a custom meta box, I don't think. At least, I think it comes standard with WordPress, since there is no add_meta_box function call for this Topics box in the custom theme.

What would be likely places in the code where I should look to debug this? I am at a loss, because this is not a problem with a custom meta box, so I'm not sure where in the custom code there may be something that interferes with the Topics box. This is probably not a WordPress bug, because the Topic does save for one of my custom post types. None of the other taxonomy meta boxes in the sidebar are failing except the one for the Topics taxonomy. For example, in the screenshot below, you see the top portion of a Countries meta box, and there is no problem with the country values saving. It's only the Topics box that fails to save, and only for some custom post types.

What are the usual suspects for debugging this? Any files in the theme I should look at? There are no javascript errors in the console, and no PHP errors in the log.

enter image description here

I've been comparing the code for a custom post type (my-theme/inc/post-types/etcetera) where the Topics check boxes will save with two where they don't save, and I can't find any discrepancy.

Here is sample code for a custom post type where the Topic will not save. Though I see no obvious discrepancies between this code and the custom post type where saving the Topic does work, and am not sure there is anything here that's relevant to the problem:

class Example_Post_Type_Program extends Example_Post_Type {

    public $name = 'program';

    public function create_post_type() {
        register_post_type(
            $this->name,
            [
                'labels' => [
                    'name'                  => __( 'Programs', 'example' ),
                    'singular_name'         => __( 'Program', 'example' ),
                    'add_new'               => __( 'Add New Program', 'example' ),
                    'add_new_item'          => __( 'Add New Program', 'example' ),
                    'edit_item'             => __( 'Edit Program', 'example' ),
                    'new_item'              => __( 'New Program', 'example' ),
                    'view_item'             => __( 'View Program', 'example' ),
                    'view_items'            => __( 'View Programs', 'example' ),
                    'search_items'          => __( 'Search Programs', 'example' ),
                    'not_found'             => __( 'No programs found', 'example' ),
                    'not_found_in_trash'    => __( 'No programs found in Trash', 'example' ),
                    'parent_item_colon'     => __( 'Parent Program:', 'example' ),
                    'all_items'             => __( 'All Programs', 'example' ),
                    'archives'              => __( 'Program Archives', 'example' ),
                    'attributes'            => __( 'Program Attributes', 'example' ),
                    'insert_into_item'      => __( 'Insert into program', 'example' ),
                    'uploaded_to_this_item' => __( 'Uploaded to this program', 'example' ),
                    'filter_items_list'     => __( 'Filter programs list', 'example' ),
                    'items_list_navigation' => __( 'Programs list navigation', 'example' ),
                    'items_list'            => __( 'Programs list', 'example' ),
                    'menu_name'             => __( 'Programs', 'example' ),
                ],
                'public' => true,
                'show_in_rest' => true,
                'menu_icon' => 'dashicons-images-alt',
                'supports' => [ 'title', 'thumbnail', 'author', 'editor', 'revisions', 'excerpt' ],
                'taxonomies' => [ 'category', 'post_tag', 'topic', 'language', 'country' ],
                'rewrite' => [
                    'slug' => 'programs',
                ],
            ]
        );
    }
}
$example_post_type_program = new Example_Post_Type_Program();
1

I don't know of any "default" "topics meta boxes" in WordPress. Have you switched to a default WordPress theme to see if this still shows up? Sounds like theme, or some other plugin is adding that (post a screenshot to help us ... help you).

You should do a search in folder (using whatever IDE you have) looking for a string, or something else you see on the screen for the "topics" that way you can pinpoint who/what is adding that (even if it is core).

Chances are it's using either save_post_{$POST_TYPE} or save_post hook to update any custom meta or other values ... but even then without knowing "where" the "topics" is coming from it's hard to say.

You can get a free/trial copy of PHPStorm EAP (Early Access Program) from here: https://www.jetbrains.com/phpstorm/eap/

Setup xDebug handling and add a breakpoint and literally walk through your code until you find the issue. Will save you hours of time, not only now, but in the future as well.

You can also use Local by Flywheel to setup a local WordPress installation and they have an addon to automatically setup xDebug in PHPStorm.

  • Thanks for this response! The custom post types are in the theme files, so switching to another theme won't help me debug. I have tried to grep for various strings in all the directories where I think custom code might be found (I didn't develop the site), but have not found anything relevant yet. I will add a screenshot and try to improve my question a bit. – arnoldbird Feb 20 at 13:53
  • Yeah so somewhere somehow the taxonomy topic is being created .. maybe it's a plugin someone installed to add custom taxonomies (why you can't find it in code). You can try doing a search for register_taxonomy to see if there's any hard coded registration of taxonomies ... but it sounds like it may be a plugin dynamically doing it. I suggest searching the ENTIRE WordPress directory, not just specific folders .. you never know where it could be located – sMyles Feb 20 at 18:49
  • I see where the taxonomy is created. It's in the theme. There is a class with a function create_taxonomy(). That class is extended by a class that created the 'topic' taxonomy. I see nothing in that class of interest, other than possibly this: $this->object_types = [ 'post' ] // This looks to me like this taxonomy can only be used for posts, and not for the custom content types. However, the taxonomy is working for at least one of the custom content types. I have been grepping for the name of the custom content type where the topic does save, but have not found anything of interest. – arnoldbird Feb 20 at 19:15
  • Looks like the Topics meta box is added by a plugin called Classic Editor. It enables "the old-style Edit Post screen layout". When I deactivate this plugin, there is no Topics meta box. I will see what's going on with this plugin. – arnoldbird Feb 20 at 19:25
  • @arnoldbird hmm weird, that's what reverts to classic editor from Gutenburg -- so odd that is what is adding it (unless topic is some old taxonomy i'm not aware of) ... it's also possible that another plugin/theme is filtering on something in the Classic Editor plugin to add that as well (something to keep in mind while debugging) – sMyles Feb 20 at 19:48

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.