List of Custom Post Type categories inside WP metabox?

Hi there,

In my newest theme, I would like the user to select with custom post type categories to show on the page, but could not find a way.

I would really appreciate if you could point me in the right direction.

FYI, I am using the metabox class here: http://www.deluxeblogtips.com/2010/05/howto-meta-box-wordpress.html

You could add in the metabox a select input populated with all the post types your theme has, that will be stored as a meta value for that page, then you can get that value in the page.php file and do a custom query with the post type the user selected.

Good luck.


$meta_boxes[] = array(
    'id' => 'my-meta-box-2',
    'title' => 'Custom meta box 2',
    'pages' => array('post', 'link'), // custom post type
    'context' => 'normal',
    'priority' => 'high',
    'fields' => array(
        array(
			'name' => 'Categories',
			'id' => $prefix . 'cats',
			'type' => 'taxonomy',					// taxonomy
			'options' => array(
				'taxonomy' => 'yourtaxonomy',			// taxonomy name
				'type' => 'select',					// how to show taxonomy? 'select' (default) or 'checkbox_list'
				'args' => array()					// arguments to query taxonomy, see http://goo.gl/795Vm
			),
    )
);

Excerpt from here.

You can choose which taxonomy and also have a checkbox list instead of a select :slight_smile:

Thanks digitalimpact,

So if I have a custom post type called “portfolio” and its “portfolio-categories”, do I replace “yourtaxonomy” with “portfolio”?

And do I need any variables in the args array?

Yup, just replace “yourtaxonomy” with the name of the taxonomy you registered for the Portfolio custom post type.

I think it should work without anything in the args array; that one might be used for advanced stuff like getting terms and so on. args is not mandatory as far as I know, try it and tell us :slight_smile:

Thanks again, I am using the “checkbox_list” type, so the user can select multiple values, but the post meta is not returning an array.

It returns a single value of the first selected checkbox.

are you looking to put a dropdown of categories inside the meta box, or just have the categories on the side? where they usally are.

Found it!

WP function has the option to return string or array: http://codex.wordpress.org/Function_Reference/get_post_meta

chrismccoy said

are you looking to put a dropdown of categories inside the meta box, or just have the categories on the side? where they usally are.

This is what I am working on, which will allow the user to have unlimited Portfolio pages:

BUT, its not working because the get_categories “exclude” functionality is not working!