• Resolved magnetmedia

    (@magnetmedia)


    Hi,

    I created a custom post type with two taximonies. I’m struggling to figure what the url is to the taximony pages, as well as setting templates for them. Sometimes I get 404 pages or get redirected to another page on my site.

    blah.com/video-index (CPT)
    blah.com/video-index/technology (taximony, sometimes shows 404/redirects/or the incorrect template).

    I’ve got archive-cpt.php and taximony-“name of taximony”.php. placed in the right folder of my FTP.

    I’m definitely missing something. I’m just not sure what it is.

    Note that I do have 5 other CPT and taximonies working correctly on my site.

    https://www.ads-software.com/plugins/custom-post-type-ui/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    One thing to keep in mind is that there isn’t a taxonomy archive like there is a post type archive. What that means is that no list of all posts of all terms of a given taxonomy. There are term taxonomy archives, where you get all of the posts for a given term in the taxonomy. If I’m reading correctly, you’ve been trying for the taxonomy archive version.

    Thread Starter magnetmedia

    (@magnetmedia)

    How do I go on about viewing and placing a template for the term taxonomy pages?

    My two taxonomies are: ‘video-client’ and ‘video-service’

    Would [blah.com/video-index/video-service/technology] be the correct url structure to visit this page? I tried visiting it, but it just shows up as as a 404 page.

    And also, for the individual post, it doesn’t seem to be changing to the correct template. Am I naming my files wrong? (‘archive-video-index.php’ or ‘taxonomy-video-clients.php’)

    Oh, and oops. I just realized I’ve been spelling taxonomy wrong. lol. Thanks for the quick reply.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I believe the taxonomy term archives would be found at https://www.yourdomain.com/taxonomy_slug/term_slug, without the post type in the URL.

    I would recommend using underscores instead of dashes for your post type and taxonomy slugs. It could be contributing to some issues here. If your slugs have underscores in them already, then those spots need to match in your template file name as well.

    From the register_taxonomy codex page:
    “The name of the taxonomy. Name should only contain lowercase letters and the underscore character, and not be more than 32 characters long (database structure restriction).”

    It is possible that “taxonomy-video-clients.php” is getting interpreted as the taxonomy of “video” and a term of “clients” instead of one taxonomy of “video-clients”. Good overall reference: https://developer.www.ads-software.com/themes/basics/template-hierarchy/

    Thread Starter magnetmedia

    (@magnetmedia)

    Great! I got it to work.

    Another question. I’m having trouble displaying multiple posts connected to my taxonomy. I tried adding: 'posts_per_page' => '-1',to the array, but it didn’t work. Am I going about this the wrong way?

    <div class="container-fluid section-with-search section-dark">
    	<div class="row mm-grid">
                        <?php
                        $the_query = new WP_Query( array(
                            'post_type' => array('video-index'),
                            'tax_query' => array(
                                array(
                                    'taxonomy' => $term->taxonomy,
                                    'field' => 'slug',
                                    'terms' => $term->slug,
                                ),
                            ),
                        ) );
    
                        ?>
    
                        <ul class="post-list">
    			<li>
    			<a class="post-title" href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    			<?php if ( has_post_thumbnail() ) : ?>
    			<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    			<?php the_post_thumbnail(); ?>
    			</a>
    
    			<?php endif; ?>
    			</li>
    		</ul>
    	</div>
     </div>
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I would re-read the standard loop example from https://codex.www.ads-software.com/Class_Reference/WP_Query#Standard_Loop because it looks like you missed some details.

    Specifically, you’re missing parts of the following:

    if ( $the_query->have_posts() ) {
    	echo '<ul>';
    	while ( $the_query->have_posts() ) {
    		$the_query->the_post();
    		echo '<li>' . get_the_title() . '</li>';
    	}
    	echo '</ul>';
    } else {
    	// no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();

    Notice how they’re doing things like $the_query->have_posts() and whatnot. That’s making the code act on this new WP_Query object. In your case, it’d be the taxonomy query you’re making. With what you have above, your use of the_permalink() and other familiar loop functions are acting on the WP_Query object for the page you’re on.

    Hopefully something like the following gives you the results you’re wanting.

    <div class="container-fluid section-with-search section-dark">
    	<div class="row mm-grid">
                        <?php
                        $the_query = new WP_Query( array(
                            'post_type' => array('video-index'),
                            'tax_query' => array(
                                array(
                                    'taxonomy' => $term->taxonomy,
                                    'field' => 'slug',
                                    'terms' => $term->slug,
                                ),
                            ),
                        ) );
    
                        if ( $the_query->have_posts() ) :
                        ?>
                        <ul class="post-list">
                        <?php
                            while( $the_query->have_posts() ) :
                                $the_query->the_post();
    			<li>
    			<a class="post-title" href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    			<?php if ( has_post_thumbnail() ) : ?>
    			<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    			<?php the_post_thumbnail(); ?>
    			</a>
    			<?php endif; ?>
    			</li>
                        </ul>
                        <?php endwhile; endif;
                        /* Restore original Post Data */
                        wp_reset_postdata();
                        ?>
    	</div>
     </div>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Taximony pages’ is closed to new replies.