Dynamic page slug for Custom Taxonomies?

I have a custom page “fine-art”, which lists the different types of fine art that we produce based on the custom-taxonomy “fine_art_category”. Some of the custom taxonomies are wood, metal, Fine Art Editions/Album, Fine Art Editions/Metal.

The Fine Art Editions taxonomy doesn’t have anything in it, it only has subcategories Album and Metal.

Read More

Is it possible to create a slug for each of the custom taxonomies, so for example http://www.com/fine-art/wood and http://www.com/fine-art/metal. And in each page lists all of the posts with the custom taxonomy of wood. Or do I need to create a custom page for each category to make this happen?

This is my custom page for fine-art, which just lists the last five posts in each custom taxonomy.

<?php
/*
Template Name: Beta Fine Art
*/

$terms = get_terms("fine_art_category");
$count = count($terms);
if ( $count > 0 ){
foreach ( $terms as $term ) {
echo "<h3>" . $term->name . "</h3>"; 


$args = array(
    'post_type' => 'fine-art',
    'posts_per_page' => 5,
    'tax_query' => array(
        array(
            'taxonomy' => 'fine_art_category',
            'field' => 'slug',
            'terms' => $term->slug
        )
    )
);

$wp_fineart_query = new WP_Query( $args );

while( $wp_fineart_query->have_posts() ) : $wp_fineart_query->the_post(); ?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php
endwhile;
}
}
?>

Related posts

Leave a Reply

1 comment

  1. WordPress already does all this by default. There is not reason for you to need to modify the slugs work, you just need to configure your custom taxonomy to have the rewrite slug ‘fine-art’.

    I think you can then just create your page with that same ‘fine-art’ slug. I believe it should still find that page regardless of the taxonomy name having the same slug. Then all you need to do in your template is what you appear to already be doing, which is generate the links for the terms you want to show.

    If this still is not working, it might be helpful for you to include your custom taxonomy declaration.