0

I have a custom post type movies that I have defined in function.php

function create_post_type() {
  register_post_type( 'movies',
  array(
    'supports' => array('title', 'editor' , 'excerpt' , 'custom-fields'),
    'labels' => array( 'taxonomies'  => 'mvgen',
      'name' => __( 'movies' ),
      'singular_name' => __( 'movies' ),
    ),
    'public' => true,
    'has_archive' => true,
  )   
  ); 
} 
add_action( 'init', 'create_post_type' );

Now the archive page and single page are working good. But I have defined two custom taxonomies for this post type, for example "DRAMA" and "Rock."

I want when user click on this taxonomy they get all post related to that particular taxonomy.
For that I have created page taxonomy-mvgen-drama.php which is copied below:

  <?php get_header(); ?>
  <section class="blog_sect">
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

      <?php the_title(); ?>
      <?php the_content(); ?>
      <?php echo get_the_date(); ?>
      <p>CATEGORY: <?php the_category(', '); ?></p>
      </p>    

      <!-- ----------------printing taxonomy for a specifuic post------------------ -->
      <?php

      ?>
      <br>
      <p><?php echo "LANGUAGES :"." ".get_the_term_list($post->ID, 'mvgen', '' , ' , ') ?></p> 

      </b>
    <?php endwhile; ?>
    <?php endif; ?>
    <?php get_footer(); ?>
  </section>
  <?php get_footer(); ?> 

But whenever I click on this taxonomy it doesn't take me to taxonomy-mvgen-drama instead it takes me to index page with the url http://localhost/movies/mvgen/rock/

Can you help me with this?

0

You haven't posted here the code for registering a taxonomy, but I'm going to assume that's working. In your code for creating the custom post type, you have the taxonomies inside the labels array. This needs to be at the top level. Additionally, the value of taxonomies needs to be an array, even if it only has 1 item in it. See below. More information.

function create_post_type() {
  register_post_type( 'movies',
  array(
    'supports' => array('title', 'editor' , 'excerpt' , 'custom-fields'),
    'taxonomies'  => array( 'mvgen' ),
    'labels' => array(
      'name' => __( 'movies' ),
      'singular_name' => __( 'movies' ),
    ),
    'public' => true,
    'has_archive' => true,
  )   
  ); 
} 
add_action( 'init', 'create_post_type' );

Your template name looks correct to me, but you can always reference the template hierarchy to make sure you're targeting the correct file name.

In addition, I find the Show Current Template plugin helps when trying to determine what file is being used.

|improve this answer|||||
0

According to the Wordpress Codex page on Template Hierarchy, you create a template file with the name of taxonomy-mvgen.php. WordPress will use that to display the archive for that taxonomy. for example "DRAMA" and "Rock." You can also use taxonomy-mvgen-drama.php and to taxonomy-mvgen-rock.php create templates for specific terms in your taxonomy.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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