0
votes

Recently I created a custom post type in wordpress and added taxonomies named category and tags. Well, the newly created custom post type is showing in the admin panel of my wordpress. It also allows me to add post and fetch them from database and do all the things that a default wordpress post offers. Only the thing that I couldn't do is whenever I view my newly created category from custom post type, it redirects me to the page which says nothing found.

However, few months back for the same issue I found a solution in wordpress.org forum, where someone has suggested to place flush_rewrite_rules() just below the register_post_type(); statement. I tried to implement it to resolve my issue but it didn't work.

Can anybody please help me addressing this issue?

1
Can anybody help me please...I am waiting for your answers :-)user3404974

1 Answers

0
votes

let me explain with example :

create custom post with name of career in function.php

function career() {
    $args = array( 'public' => true, 'label' => 'Career', 'publicly_queryable' => true,
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true,
 'thumbnail' => true,
 'supports' => array( 'title', 'editor','thumbnail', 'excerpt','revisions', 'custom-fields')
 );
    register_post_type( 'career', $args );
}
add_action('init', 'career');

Now create texonomy of that post

//create two taxonomies, genres and writers for the post type "book"
function create_career_taxonomies() 
{
  // Add new taxonomy, make it hierarchical (like categories)

  register_taxonomy('career_cat',array('career'), array(
    'hierarchical' => true,

    'show_ui' => true,
    'show_admin_column' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'career_cat' ),
  ));

}


//hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_career_taxonomies', 0 );

Let's call dynamic category with it's post. Make sure your category has atleast one post.

    <?php
     $taxonomy = 'career_cat';
     $tax_terms = get_terms($taxonomy);

      foreach ($tax_terms as $tax_term) { ?>
        <ul>
           <li>
         <?php $query =  query_posts("post_type=career&career_cat=".$tax_term->name);
 if ( have_posts() ) { while ( have_posts() ) { the_post(); $post = get_post();  ?>
              <ul><li class="fl tr">
                   <a href="<?php the_permalink(); ?>"><?php  the_title(); ?></a>
                  </li></ul>
                  <?php }} ?>
                 </li>
                </ul>
       <?php  }   ?>