Support » Plugins and Hacks » Hacks » Custom Post Type

Custom Post Type

  • Hi,

    First I would like to apologies if I made a thread in wrong forum. I got problem based my custom post type and plugin. I have setup my custom post type called Audio and in this custom post type got Audio, Add New Audio and Audio Genres.

    Audio[Custom Post Type]
    – Audio
    – Add New Audio
    – Audio Genres

    The problem is, I’m using an autopost plugin and the plugin just appear my WordPress Categories not my Audio Genres. I’ve looked up my database on wp_terms, there is 2 categories called Acoustics. And the ID was 7 and 64. 7 come from WordPress Categories and 64 come from Audio Genres that I set in my Custom Post Type. So, how can I let the plugin show up my Audio Genres categories.

    This is the source code from the plugin.

    // categories
    $source_data->categories = array();
    $cats_array = $this->WPDB->get_results(sprintf("SELECT <code>category</code> FROM <code>%s</code> WHERE <code>source</code> = %d", $this->tables['categories'], $source_id));
    	if (is_array($cats_array)) {
    		while ($cat = array_shift($cats_array))
    			$source_data->categories[] = $cat->category;

    And this is the custom post type source code for your reference.

    add_action('init', 'posttype_audio');
    function posttype_audio() {
            $labels = array(
                    'name' => __('Audio', 'audio_mtlabs'),
                    'singular_name' => __('Album', 'audio_mtlabs'),
                    'add_new' => __('Add Album', 'audio_mtlabs'),
                    'add_new_item' => __('Add New Album','audio_mtlabs'),
                    'edit_item' => __('Edit Album','audio_mtlabs'),
                    'new_item' => __('New Album','audio_mtlabs'),
                    'view_item' => __('View Details','audio_mtlabs'),
                    'search_items' => __('Search Audio','audio_mtlabs'),
                    'not_found' =>  __('No Audio was found with that criteria','audio_mtlabs'),
                    'not_found_in_trash' => __('No Audio found in the Trash with that criteria','audio_mtlabs'),
                    'view' =>  __('View Album', 'audio_mtlabs')
            $imagepath =  get_stylesheet_directory_uri() . '/images/posttypeimg/';
            $args = array(
                    'labels' => $labels,
                    'description' => 'This is the holding location for all Albums',
                    'public' => true,
                    'publicly_queryable' => true,
                    'exclude_from_search' => false,
                    'show_ui' => true,
                    'rewrite' => true,
                    'hierarchical' => true,
                    'menu_position' => 5,
                    'menu_icon' => $imagepath . '/aud.png',
                    'supports' => array('thumbnail','title','comments','revisions')
    		$labels = array(
    				'name' => _x( 'Audio Genres', 'taxonomy general name' ),
    				'singular_name' => _x( 'Audio Genre', 'taxonomy singular name' ),
    				'search_items' =>  __( 'Search Audio Genres' ),
    				'all_items' => __( 'All Audio Genres' ),
    				'parent_item' => __( 'Parent Audio Genre' ),
    				'parent_item_colon' => __( 'Parent Audio Genre:' ),
    				'edit_item' => __( 'Edit Audio Genre' ),
    				'update_item' => __( 'Update Audio Genre' ),
    				'add_new_item' => __( 'Add New Audio Genre' ),
    				'new_item_name' => __( 'New Audio Genre Name' ),
    		register_taxonomy( 'audio_genre', array( 'audio' ), array(
    				'hierarchical' => true,
    				'labels' => $labels, /* NOTICE: Here is where the $labels variable is used */
    				'show_ui' => true,
    				'query_var' => true,
    				'rewrite' => array( 'slug' => 'audio_genre' ),
Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi!
    I need help with my category page blog post. Blog page site http://www.deepgreenarts.com/north-carolina. I have 4 categories; attractions, waterfalls, exhibits, and souvenir. I don’t understand why all of my post are showing in all of my pages? I already set my settings of all my post assigned to each category but it doesn’t seem working. Please help…

    @inswins: Categories are a particular type of taxonomy. You are creating a different taxonomy called audio genre, which is why the plugin is not showing it. You should add audio genre to the category taxonomy.

    @greendp_4: Next time, please start your own new topic instead of latching on to someone else’s 😉 The permalink parser will not recognize categories unless they are preceded by the pseudo folder “/category/” in the link. Note how the category links in your side bar are constructed. You need to construct the menu links the same way. If you find the presence of a category pseudo folder in your menu links distasteful, you can use .htaccess tricks to recognize your few categories and insert the pseudo folder behind the scenes before WordPress gets a hold of it.

    Thank you so much for your help. I got my website fix. Take a look http://www.deepgreenarts.com

    @bcworkz: Do you mean I have to register my audio genre in normal WordPress Categories? Based on the code as below:

    register_taxonomy( 'audio_genre', array( 'audio' ), array(
    				'hierarchical' => true,
    				'labels' => $labels, /* NOTICE: Here is where the $labels variable is used */
    				'show_ui' => true,
    				'query_var' => true,
    				'rewrite' => array( 'slug' => 'audio_genre' ),

    register_taxonomy is a custom taxonomy right? How can I register to the category taxonomy?

    Yes, sounds like you get the picture now.

    To add to the category taxonomy, use wp_insert_category(). If categories are not showing up for your custom post type, I believe you use register_taxonomy_for_object_type().

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom Post Type’ is closed to new replies.