0

I have a custom post type Movie and a custom taxonomy Genre with some terms (like Sci-fi). I want to create a custom template for show all the movies of a particular genre.

I read that it's just a matter of create a file called taxonomy-genre.php with a loop inside. I did it, I navigate to domain.com/movie/sci-fi but I get 404 (already tried to flush permalinks).

What is the right way?

/*
 * Add Custom post types
 */
function n2_custom_post_types() {

  $types = array(

    array('type'          => 'movie',
          'typePlural'    => 'movies',
          'labelSingle'   => 'Movie',
          'labelPlural'   => 'Movies'
      )

  );

  foreach ($types as $type) {

    $typeSingle = $type['type'];
    $typePlural = $type['typePlural'];
    $labelSingle = $type['labelSingle'];
    $labelPlural = $type['labelPlural'];

    $labels = array(
     //...
    );

    $args = array(
      'labels'        => $labels,
      'description'   => 'Holds our products and product specific data',
      'public'        => true,
      'supports'      => array( 'title', 'author', 'editor', 'thumbnail', 'excerpt', 'comments', 'page-attributes' ),
      'has_archive'   => true,
      'menu_position' => 5,
      'rewrite'       => true
    );

    register_post_type( $typeSingle, $args );

  } // end foreach

}
add_action( 'init', 'n2_custom_post_types' );



/*
 * Add Custom Taxonomies
 */
function n2_custom_taxonomies() {

  $taxonomies = array(

    array(
      'name'   => 'genre',
      'single' => 'Genre',
      'plural' => 'Genres',
      'cpt'    => 'movie' )
  );

  foreach ($taxonomies as $taxonomy) {

    $name = $taxonomy['name'];
    $single = $taxonomy['single'];
    $plural = $taxonomy['plural'];
    $cpt = $taxonomy['cpt'];

    $labels = array(
     // ...
    );

    $args = array(
      'labels'            => $labels,
      'hierarchical'      => true,
      'show_ui'           => true,
      'show_admin_column' => true
    );

    register_taxonomy( $name, $cpt, $args );

  } //foreach
}
add_action( 'init', 'n2_custom_taxonomies', 0 );
  • What do you mean by doesn't work. doesn't work can mean a million things – Pieter Goosen Jul 22 '15 at 19:04
  • Update post, check it please – Fred K Jul 22 '15 at 19:08
  • It seems like a rewrite issue or incorrect values when you registered your custom taxonomy/post type. If you flushed permalinks and still getting 404, post your code for registering your custom post type and taxonomy. – Pieter Goosen Jul 22 '15 at 19:14
  • Already tried permalink flush. Added code. – Fred K Jul 22 '15 at 19:20
  • You are totally registering your cpt and taxonomy wrong. Recheck the codex on these issues – Pieter Goosen Jul 22 '15 at 19:25

Your Answer

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

Browse other questions tagged or ask your own question.