Custom Post Type with metaboxes (no content) only?

I have a Custom Post Type called “cities”.

Each city has: Name, Population, Coordinates and so forth. I don’t want users to be able to add their custom content there (using wp-content editor, HTML or the Visual one).

Read More

What’s the best approach to this? Should I hide the text editor in CSS and then place (around 30) metaboxes on each page? Would 30 metaboxes hit theme’s performance hard compared to normal posts? I’m aiming for tens of thousands of posts, 30 metaboxes each. Any hints?

Related posts

1 comment

  1. To create a custom post type without the editor, simply omit 'editor' in the 'supports' argument when you register the custom post type:

    $args = array(
        // only title field will be visible
        'supports' => array( 'title' ),
        // other args here...
    );
    register_post_type( 'cities', $args );
    

    As for your meta data, that is a lot, but I wouldn’t say it’s too much. And you don’t need to create 30 meta boxes for 30 pieces of data, you can render all of the fields in a single meta box.

    Think about how you’ll need to use that data later- If you need to query and sort on the data via a meta_query, then it should be its own field. But if there’s data that will only be displayed but not queried on, you can save that all as an array under a single key:

    $data = array(
        'street' => 'fake street',
        'number' => 123,
        'fruit' => 'pears'
    );
    update_post_meta( $post_id, 'some_data', $data );
    

    WordPress will take care of converting the array to a storable value, and converting it back to an array when the data is loaded.

Comments are closed.