Forums

Can we have categorized custom posts? (5 posts)

  1. iamopensource
    Member
    Posted 1 year ago #

    Hi,

    I created Custom Post :

    //Add custom post
    add_action( 'init', 'create_post_type' );
    function create_post_type() {
    	register_post_type( 'gb_cmspage',
    		array(
    			'labels' => array(
    				'name' => __( 'CMSPages' ),
    				'singular_name' => __( 'CMSPage' ),
    				‘show_ui’ => true,
    				‘capability_type’ => ‘post’,
    				‘hierarchical’ => false,
    				‘rewrite’ => true,
    				‘supports’ => array(‘title’, ‘editor’, ‘thumbnail’, ‘custom-fields’)
    			),
    		'public' => true
    		)
    	);
    }

    This works fairly fine, but I do not see an option to choose a category the way we have for Post.

    How can I have custom categorized post for my custom content type?

    Regards

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    'taxonomies' => array( 'post_tag', 'category'),

    added in there will bring in normal tags and cats.... are you looking for custom taxonomies?

    Also
    http://codex.wordpress.org/Function_Reference/register_post_type#Example
    May wanna read up on CPTs a bit more, looking at your code, you seem to be trying to pass a bunch of stuff into the labels array that don't belong there

  3. iamopensource
    Member
    Posted 1 year ago #

    Thanks Rev,
    Unfortunately, adding
    'taxonomies' => array( 'post_tag', 'category'),
    did not show Categories for me.

    Am I doing something wrong?

    Thanks

  4. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    if you just added it to the code above, yes.

    As I stated, you are adding your supports, rewrite, etc parameters to your labels array, which doesn't work.

    Read the link I posted, or even look at my code here:
    http://wordpress.pastebin.com/DfiEScZx

    See how this stuff:

    ‘show_ui’ => true,
    				‘capability_type’ => ‘post’,
    				‘hierarchical’ => false,
    				‘rewrite’ => true,
    				‘supports’ => array(‘title’, ‘editor’, ‘thumbnail’, ‘custom-fields’)

    is outside of the labels array, it should all be hanging out with your public => true line

  5. iamopensource
    Member
    Posted 1 year ago #

    Thanks Rev,
    You exactly pointed out the problem. I got the Categories.

    The only problem I've now is "the URL".
    While editing the post I see:
    Permalink: http://localhost/mysite/gb_cmspage/my-cms-page

    I selected category called "Content".

    So it should be:
    Permalink: http://localhost/mysite/content/my-cms-page

    Clicking the View takes me to
    http://localhost/mysite/gb_cmspage/my-cms-page that says
    "Sorry, no posts matched your criteria."

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic