Support

Account

Home Forums Front-end Issues Taxonomy term archive page

Solving

Taxonomy term archive page

  • Hey guys! Thanks for taking a look. Have looked around but can’t find an answer. Support has been great about getting back to me with ideas, but 3 days later, no progress…

    I can’t get a taxonomy term archive to show… any results.

    I have a custom post type, “Collabs”. Collabs has a custom field taxonomy, “Location”. This works well and shows up nicely on single posts.

    I would like the Location term, ie “Denver”, clickable so users can browse all Denver tagged posts. I have iterated over the loop and query 1,000x to no avail.

    Any thoughts??

    (file name taxonomy-location.php)

    $the_query = new WP_Query( array(
            'post_type' => 'collab',
            'tax_query' => array(
                array (
                    'taxonomy' => 'location',
                    'field' => 'slug',
                    'terms' => 'denver-co',
                )
            ),
        ) );
        
        while ( $the_query->have_posts() ) :
            $the_query->the_post();
                echo "success";
        endwhile;
  • First, you should not be needing to do a query if the template file name is taxonomy-location.php. WP is already doing this query. You should simply need to do a loop over the posts

    
    while (have_posts()) {
      the_post();
    }
    

    How are the terms in this taxonomy added? Standard WP meta box or ACF custom field? If a custom field do you have save and load terms enabled?

  • Thanks a lot for the response, John. I’ve been wracking my brain on this.

    I started out with a basic page and had no results. Trouble shooting brought me to the custom query.

    I’ve updated the template to just be this and still no results.

    ‘<?php
    /*
    Template Name: Location
    */
    get_header(); ?>

    <div id=”primary” class=”site-content”>
    <div id=”content” role=”main”>

    <?php while (have_posts()) {
    the_post();
    } ?>

    </div><!– #content –>
    </div><!– #primary –>

    <?php get_sidebar(); ?>
    <?php get_footer(); ?>’

  • If the slug for the taxonomy is ‘location’ and you have a file named ‘taxonomy-location.php’ then this file should be loaded, https://developer.wordpress.org/themes/basics/template-hierarchy/, unless you have something else going on. I know this may seem like I’m asking a stupid question, and you may have already gone over this before, but are you sure this file is being loaded?

  • There are no stupid questions when debugging 🙂 Thanks for the reply.

    The file is indeed named that and I wrote the file name to the screen to ensure:

    https://www.fshneco.com/v2/location/denver-co/

    The site is setup in a “v2” directory, I can’t imagine that would throw things off… but it is a thing.

    file name “taxonomy-location.php”

    Code:

    <?php
    /* 
    Template Name: Location
    */
    get_header(); ?>
     
    <div id="primary" class="site-content">
        <div id="content" role="main">
            <p>This is the Locations template ('taxonomy-location.php')</p>
            
           <?php while (have_posts()) {
              the_post();
            } ?>
        
         
        </div>
    </div>
     
    <?php get_footer(); ?>

    Thanks again for looking at this.
    Morgan

  • So then the problem is that WP is not finding any posts with that term.

    This goes back to my last question. How are the terms selected for the post?

    Are you using the standard WP taxonomy meta box? it is on the right where categories and tags would usually be. Or are you using an ACF taxonomy field?

  • It’s an ACF field attached to a custom post type (Custom Post Type UI) “collab”.

  • Turn the settings for save and load terms to on, then re-save all of the posts. This is required to have ACF create the relationship between the posts and terms.

  • Will try that now. Previously, when I tried that, the data stopped displaying on the front end single post. Will try to resave and recreate the posts if need be.

  • I tried it and no luck. I do have Return Value set to Term Object. I switched to Term ID and it didn’t have any effect.

  • Are posts getting assigned to the terms? In the left admin menu go to Collabs => Locations. Does is show the number of posts assigned to each location?

  • It does show the number attached to each term. Have found the issue to be with my theme. I’m using Divi. When I switch to twenty-sixteen the tax term page shows results. So now I am in touch with Divi trying to sort. Will follow up with findings. Appreciate your help thus far!

Viewing 12 posts - 1 through 12 (of 12 total)

The topic ‘Taxonomy term archive page’ is closed to new replies.