First, WordPress does not offer any built-in solution to displaying posts of a specific post type and a specific taxonomy term. I'm talking about something like get_term_archive_link_for_post_type( $term, $post_type )
or so.
So you have to do this yourself.
Of course, you could create a page, name it Construction Projects, give it a new page template, in which you set up a custom query and display exactly what you want to. But that's not even necessary.
WordPress can handle several query vars—one of these is the one your taxonomy
creates.
Suppose you have a Custom Post Type with the slug projects
.
Then you have a Custom Taxonomy having the slug project_type
.
And you have a term with the slug construction
in this very taxonomy.
Then visiting ?post_type=projects&project_type=construction
will display an archive of all Projects having (at least) Construction set as Project type.
WordPress will interprete this query as a Term archive and hence rewrite the URL according to your permalink settings, and attach the post type as query var to the URL. In the usual case, this would lead to /project_type/construction?post_type=projects
.
Note: You can explicitly alter the query var for a custom taxonomy. In that case, using the taxonmy slug as query var (e.g., project_type=construction
) won't work any longer. You have to use the query var that you explicitly defined using register_taxonomy
then.
And here is some example of setting up a link list for all terms of a specific taxonomy:
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => TRUE,
'fields' => 'all',
);
$terms = get_terms( 'project_type', $args);
if (
! is_wp_error( $terms )
&& ! empty( $terms )
) {
echo '<ul>';
foreach ( $terms as $term ) {
$url = get_term_link( $term );
if ( is_wp_error( $url ) ) {
continue;
}
$url = add_query_arg( 'post_type', 'projects', $url );
printf(
'<li><a href="%s">%s</a></li>',
$url,
$term->name
);
}
echo '</ul>';
}