Reputation: 5483
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".
Upvotes: 0
Views: 922
Reputation: 7869
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();
}
?>
Upvotes: 1