• Resolved Guido

    (@guido07111975)


    Hi,

    My plugin uses register_post_type to register a custom post type. It also has a few custom fields, which are being added via add_meta_boxes. So far so good.

    But I’ve read that the supports array of the custom post type should contain ‘custom fields’ in order to support the REST API.

    So I’ve added this while registering the post type. But now a new panel is added at the edit screen (Custom Fields), which contains a duplicate set of my custom fields. Doesn’t look nice, and I know I can hide this panel again. But that’s the only thing I can do, hide it? Is there a way to hide this panel by default?

    Guido

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    Guido my friend!

    You can use remove_meta_box() to remove the default meta box. Do so from the “add_meta_boxes” action. Use a late priority arg when adding your callback to help ensure the box is really added before trying to remove it.

    If you’re unsure of the correct args to pass to the function, var dump global $wp_meta_boxes to see how it was saved.

    Thread Starter Guido

    (@guido07111975)

    Hi BC,

    I wasn’t aware of this! So thank you, works like a charm.

    But I don’t want to remove the added support for custom fields. I hope/guess this action only removes the meta box, not the support itself?

    Guido
    ps. did you read my latest reply regarding the visible Quick Edit bar?

    Moderator bcworkz

    (@bcworkz)

    The support setting is part of post type internal data and is unaffected by what happens with meta box internal data. I’ve not double checked to be absolutely sure, but I’m very confident it is so.

    Sorry, I missed the notifications from your other topic somehow. I’m glad you found the extended view setting. I too did not realize it’s there. Today is the first time I even looked at list table screen options!

    Thread Starter Guido

    (@guido07111975)

    Hi BC,

    I thought so, but was not sure. But after reading more about the remove_meta_box function, I’m pretty sure this will not affect it.

    FYI: did stumble upon another minor issue, after removing the metabox. So I have created a ticket for it (link).

    Regarding the extended view:
    I spent several hours debugging my test website (even cleaned the DB), but finaly found it after comparing the edit screens of 2 websites.

    Guido

    Moderator bcworkz

    (@bcworkz)

    There are so many little glitches in the block editor 🙁 In case you were not aware, block editor development is managed in GitHub, where you can raise issues instead of using Trac.
    https://github.com/WordPress/gutenberg/issues
    My understanding is GitHub issues are preferred over Trac, but it’s not wrong to use Trac. Just don’t use both for one issue 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom post type with custom fields’ is closed to new replies.