0

I'm working on a Woocommerce website and created a new taxonomy activity. I've added that taxonomy to the post type Product.

So a Product can have one of the following activity:

  1. Museum
  2. Food & Drinks
  3. Attractions
  4. Guided tours

To show all the Products, I've created taxonomy-activity.php which already shows all the products that have an activity taxonomy.

But I have to have all the Products with taxonomy Guided tours on a seperate page. And all the others on the other page. So there will be 2 pages: One page will be called Guided tours which only shows the guided tours and the other is called Activities.

Is it correct to do this with the taxonomy-{slug}.php or should I create a new page. For example: page-guidedtours.php which loops through all the Product with Guided tours taxonomy. And the other page page-activities.php which loops through all the Products without Guided tours taxonomy.

Sidenote: I'm using the plugin FacetWP in order to show the Product and created filters. So the query is created with the plugin and then the list of products in shown with a shortcode.

My current query is:

<?php
return [
   "post_type" => [
   "product"
],
   "post_status" => [
   "publish"
],
   "posts_per_page" => "18",
   "orderby" => "title",
   "order" => "ASC",
];

I'm thinking about created 2 Facets. One facet that shows the Guided tours. So in this case I have to add the term Guided tours to the query. And then other facet without the term Guided tours.

0

To show all the Products, I've created taxonomy-activity.php which already shows all the products that have an activity taxonomy.

That's not what taxonomy-activity.php is for. That template is the template that is used for displaying posts for each activity taxonomy term. So if you view Museum activity, that template will be used to display all Museum products, or if you view the Food & Drink activity the same template will be use to view Food & Drink products.

The template itself should not be choosing which posts to display. WordPress has already done that. All this template should be used for is presenting those posts. To loop through the products that WordPress has already query, you need to just use The Loop, not a custom query:

<?php 
if ( have_posts() ) : 
    while ( have_posts() ) : the_post(); 
        // Display product content
    endwhile; 
endif; 
?>

So WordPress will automatically make an archive available for each activity taxonomy which displays products that belong to it. You should not need to create a page or template for each one.

The same applies to post types. When you register a post type, like Products, it WordPress will automatically make an archive of all Products available if has_archive is set to true or a slug. To create a unique template for this archive, you need to create archive-product.php. This will then automatically be used at https://example.com/products/, where products is the post type name, or the slug pass to has_archive.

So what you need is archive-product.php which will be used when viewing all products at something like https://example.com/products/, and taxonomy-activity.php which will be used when viewing each activity links like https://example.com/activity/museum/ or https://example.com/activity/attractions/, as examples.

When is comes to adding FacetWP support for filtering these archives, you will need to consult their documentation, since 3rd-party plugins are off topic here, but when it comes to the required built in WordPress templates you need them set up like I described as a starting point.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.