0

I've been wondering about this. In most plugins I see now, they look like CPTs but they don't have the 'published' link. They don't serve as post as well. They're just plugins that stays in the dashboard with 'Add New' link in the top of the page and column list and items can be edited when you click 'edit' just like in any other CPT.

So I'm wondering if they are CPTs? If so, is there like a tutorial out there about this?

I am thinking of creating a plugin for my site and what I want is to build a plugin that I can 'add new items' and the items are saved (and can be edited). And I can call an item via shortcodes.

I know how to create CPTs in functions.php and I've been reading about basic plugin creation and stuff. I just can't seem to find a tutorial about what I had just mentioned.

Any help would be greatly appreaciated.

  • It is pretty hard to comment on the things that "plugins you see" do. – s_ha_dum Oct 23 '13 at 3:46
0

Yes, there are lot of plugins using CPTs as data holders (e.g., Advanced Custom Field). Others, though, carefully use the class WP_List_Table to conform to the default interface (e.g., BackWPup).

When registering a post type, we have options to control its visibility and "querybility": public, show_ui, publicly_queryable and others. This is how ACF registers itself:

register_post_type('acf', array(
    'labels' => $labels,
    'public' => false,
    'show_ui' => true,
    '_builtin' =>  false,
    'capability_type' => 'page',
    'hierarchical' => true,
    'rewrite' => false,
    'query_var' => "acf",
    'supports' => array(
        'title',
    ),
    'show_in_menu'  => false,
));

So, yes, it's perfectly fine to create a CPT that appears only in the backend, and then use it in other parts of the system. For example, the Navigation Menus (wp-admin/nav-menus.php) is a CPT, and registered like:

register_post_type( 'nav_menu_item', array(
    'labels' => $labels,
    'public' => false,
    '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
    'hierarchical' => false,
    'rewrite' => false,
    'delete_with_user' => false,
    'query_var' => false,
) );

Your example, using as a Shortcode, would be something like this used in a Post or Page:

[my_shortcode id="77"]

and what it does is: get whatever information you have in your CPT with ID 77 and display it.

Forget functions.php for this kind of stuff. Research our archives on as there is plenty of material to get started, simple and complex.

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.