• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Custom Taxonomy Archive

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Custom Taxonomy Archive

This topic is: not resolved
  • This topic has 7 replies, 3 voices, and was last updated 10 years, 3 months ago by mmjaeger.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • August 9, 2014 at 9:17 pm #118014
    mmjaeger
    Member

    Hello
    I've a custom page and I like to show all pictures on that page with a certain tag - the taxonomies are called keys .

    I've put the following code into the template file:`add_action( 'pre_get_posts', 'nv_pre_get_posts' );
    function nv_pre_get_posts( $query ) {

    $query->set( 'post_type', 'attachment' );
    $query->set( 'post_status', 'publish' );
    $query->set( 'post_parent', null );
    $query->set( 'mime_type', 'image' );
    $query->set( 'orderby', 'date' );
    $query->set( 'order', 'DESC' );

    $tax_query =
    array(array(
    'taxonomy' => 'keys',
    'field' => 'slug',
    'terms' => get_query_var( 'key' )

    ));

    $query->set( 'tax_query', $tax_query );

    return $query;
    }
    `

    however, I only getting: Sorry, no content matched your criteria.

    what am I missing

    I also tried a custom loop but I could NOT get the pagination to work - always got a 404 - the first page worked just fine.

    are there any examples out there how to set up a page that would show me all the attachment with a certain tag?

    Thanks

    August 9, 2014 at 10:05 pm #118020
    Summer
    Member

    Have you tried using the taxonomy template as defined by the WordPress template Hierarchy?

    Also, is what you defined "key" or "keys"? That would make a difference... and now I'm also wondering if that would cause a namespace clash or not...

    Depending on which name your term is, you'd create a template file (say taxonomy-keys.php), and in it you'd have something like this:

    remove_action('genesis_loop', 'genesis_do_loop');
    add_action('genesis_loop', 'child_main_loop');
    function child_main_loop() {
        global $paged;
        $term = get_queried_object();
        $args = array('post_type' => 'attachment', 'taxonomy' => $term->taxonomy, 'term' => $term->slug, 'order' => 'asc', 'paged' => $paged);
        genesis_custom_loop( $args );
    }

    followed by the genesis(); call to finish things off nicely... that's the general gist of it. You could add an "orderby" in there to get whichever sort you want.


    WordPress / Genesis Site Design & Troubleshooting: A Touch of Summer | @SummerWebDesign
    Slice of SciFi | Writers, After Dark

    August 10, 2014 at 7:11 am #118045
    mmjaeger
    Member

    Thank you for replying - seem to work for the first page - however the pagination does not work - it shows up at the bottom of the page but click on e.g. page 2 leads to a 404 - any idea how to fix this?

    thanks again.

    August 10, 2014 at 9:37 am #118068
    mmjaeger
    Member

    I got one issue when putting the following code onto my page:

    add_action( 'pre_get_posts', 'nv_pre_get_posts' );
    function nv_pre_get_posts( $query ) {
    		
    	global $paged;
    	
    	$term = get_queried_object();
    	
        $query->set( 'post_type', 'attachment' );
        $query->set( 'post_status', 'all' );
        $query->set( 'posts_per_page', 16 );
        $query->set( 'orderby', 'date' );
        $query->set( 'order', 'DESC' );
        $query->set( 'taxonomy', $term->taxonomy );
        $query->set( 'term', $term->slug );
        $query->set( 'paged', $paged );
            
        return $query;
        
    }

    for some reasons, the main navigation disappears - any idea why?

    Thanks

    August 10, 2014 at 1:12 pm #118084
    Summer
    Member

    I'm using that same code on a site and pagination works just fine. What other code do you have in your template?

    I'm also not sure what you're saying... are you using the pre_get_posts function and the child loop function together?


    WordPress / Genesis Site Design & Troubleshooting: A Touch of Summer | @SummerWebDesign
    Slice of SciFi | Writers, After Dark

    August 31, 2015 at 2:21 pm #164160
    julyan
    Participant

    Summer, thanks for your code. I used the child loop function as it is, but page 2 of the archive returns a 404. Same problem as mmjaeger.

    August 31, 2015 at 2:24 pm #164162
    julyan
    Participant
    //* adds custom loop for the specific taxonomy
    remove_action('genesis_loop', 'genesis_do_loop');
    add_action('genesis_loop', 'child_main_loop');
    function child_main_loop() {
        global $paged;
        $term = get_queried_object();
        $args = array('post_type' => 'resources', 'taxonomy' => $term->taxonomy, 'term' => $term->slug, 'order' => 'asc', 'paged' => $paged);
        genesis_custom_loop( $args );
    }
    
    //* The blog page loop logic is located in lib/structure/loops.php
    genesis();

    Page 1 works great, but succeeding pages are 404s.

    August 31, 2015 at 3:56 pm #164170
    mmjaeger
    Member

    the following coded fixed it for me:

    /**
    	 * Pagination: fix pagination issue with custom taxonomy archive page
    	 */
    	add_action( 'parse_query', 'mm_parse_query' );
    	function mm_parse_query() {
    		
    		if ( ! is_tax( 'media_tag' ) )
    			return;
    		
    	    global $wp_query;
    	        
    	    $wp_query->query_vars[ 'post_type' ]   		= array( 'resources' );
    	    $wp_query->query_vars[ 'post_status' ] 		= array( 'all' );
    	    $wp_query->query_vars[ 'posts_per_page' ]	= 16;
    	
    	}

    you need to adjust the code to your settings e.g. the taxonomy name

  • Author
    Posts
Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble