Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

From some references I wrote a code for create custom post type (journal) and taxonomy using following code. It works fine. Next I am add a new category from admin side for my custom post type (journal) called featured. I can sort this post type by category on admin side Admin part. But on user side I can't list them when I am list my category which shows only post categories Like below image. Below image show list of my custom post type(journal) . How can I show this journal list by category name on user side?enter image description here

function post_type_journal()
    {

        $labels = array(
        'name' => _x('Journals', 'post type general name'),
        'singular_name' => _x('Journal', 'post type singular name'),
        'add_new' => _x('Add New', 'journal'),
        'add_new_item' => __('Add New Journal'),
        'edit_item' => __('Edit Journal'),
        'new_item' => __('New Journal'),
        'view_item' => __('View Journal'),
        'search_items' => __('Search Journal'),
        'not_found' =>  __('Nothing found'),
        'not_found_in_trash' => __('Nothing found in Trash'),
        'parent_item_colon' => ''
    );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'menu_icon' => null,
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','editor','thumbnail'),

      ); 
        register_post_type('journal', $args);
    }
    add_action('init','post_type_journal');
function themes_taxonomy() {

        register_taxonomy('article', 'journal', array(
        // Hierarchical taxonomy (like categories)
        'hierarchical' => true,
        'query_var' => true,        
        // This array of options controls the labels displayed in the WordPress Admin UI
        'labels' => array(
            'name' => _x( 'Journal Category', 'taxonomy general name' ),
            'singular_name' => _x( 'Journal-Category', 'taxonomy singular name' ),
            'search_items' =>  __( 'Search Journal-Categories' ),
            'all_items' => __( 'All Journal-Categories' ),
            'parent_item' => __( 'Parent Journal-Category' ),
            'parent_item_colon' => __( 'Parent Journal-Category:' ),
            'edit_item' => __( 'Edit Journal-Category' ),
            'update_item' => __( 'Update Journal-Category' ),
            'add_new_item' => __( 'Add New Journal-Category' ),
            'new_item_name' => __( 'New Journal-Category Name' ),
            'menu_name' => __( 'Journal Categories' ),
        ),

        'rewrite' => array(
            'slug' => 'article', // This controls the base slug that will display before each term
            'with_front' => false, // Don't display the category base before "/locations/"            
            'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
        ),
    ));
}
add_action( 'init', 'themes_taxonomy',0);  

The following is code of user side that outputs is shown in second image

$categories = get_categories($args);
  foreach($categories as $category) { 
    echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
    echo '<p> Description:'. $category->description . '</p>';
    echo '<p> Post Count: '. $category->count . '</p>';  } 


        $type = 'journal';
                echo  $cat_id=get_cat_ID('featured');
        $args=array(
                 'cat'=>$cat_id,
         'post_type' => $type,
         'post_status' => 'publish',
         'posts_per_page' => -1,
         'caller_get_posts'=> 1);

        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
         while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
          endwhile;
        }
        wp_reset_query();  // Restore global post data stomped by the_post().
        ?>
share|improve this question
1  
Please don't ignore answers to your older questions. Comment and if you got a solution, then mark it as such. Else people will stay back from answering your later questions. –  kaiser Jan 29 at 11:56

1 Answer 1

Using categories isn't the same as using a custom taxonomy. You should adapt your code to use get_terms and to query for your custom tax:

$categories = get_terms('article');
  foreach($categories as $category) { 
    $args=array(
     'article'=>$category->slug,
     'post_type' => 'journal',
     'post_status' => 'publish',
     'posts_per_page' => -1,
     'caller_get_posts'=> 1);
  }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.