0
votes

I've generated three different custom post types (e.g. books, movies, games). And I've a custom taxonomy for all of them (e.g. genre).

What I need are archives for the taxanomy based on the post types. For example: "books-genre", "movies-genre"...

Is there any solution to do that? Now I've only the taxonomy archive for "genre".

1
So you want all the taxonomy archive to have three sections (books, movies, games).serraosays
not exactly. that's what I've already done. I want a taxonomy archive for every post type. For example: only science fiction books. And I want to have own URLs for these archives like: /book-genre/science-fiction/Cray
Ok, then you just want custom post type archives with permalink modifications. It's really a two part question then: do you need help setting up custom post type archives or help setting up the permalink structure?serraosays
I think first it's about custom post type archivesCray
I know how to generate custom post type archives. the problem is the combination with the taxonomyCray

1 Answers

1
votes

The way I like to approach custom post archives is to create a custom archive template with WP_Query sections where I need them. You'd create the blank file in the root of your theme at archive-cptnamehere.php.

You might have some template partials to add in but the core of the page looks like this:

  <?php
    // 1- Get ID of the page's path by URL (reliable)
    $pagePath = $_SERVER['REQUEST_URI'];
    $pageObject = get_page_by_path($pagePath);
    $pagePathID = $pageObject->ID;

    // 2- Print page title
    $teamPageTitle = get_the_title($pagePathID);
    echo $teamPageTitle;

    // 3 - Do a query that gets the data you need
    // Args: -1 shows all locations, orders locations alphabetically by title, orders locations a-z, only query against team items
    $args = array(
      'posts_per_page' => -1,
      'orderby' => 'title',
      'order' => 'ASC',
      'post_type' => 'team',
      'meta_query'  => array(
        array(
         'key'          => 'team_page_categorization',
         'value'        => $team_page_categorization_options_array_item,
         'compare'  => 'LIKE'
        )
      )
    );
    $the_query = new WP_Query( $args );

    // 4- Setup query while loop
    if($the_query->have_posts()) {
      while($the_query->have_posts()) {
        $the_query->the_post();

        // 5- Do what you need to inside the loop


      // 6- Close it all up, don't forget to reset_postdata so you can do additional queries if necessary!    
      }
     wp_reset_postdata();
    }
  ?>