0

I've got a taxonomy archive to show custom post-types, its got a custom query calling the posts - I can't figure out where to put showposts in it.

global $wp_query; 
    $term = get_term_by( 'slug', get_query_var($wp_query->query_vars['taxonomy']), 

    $wp_query->query_vars['taxonomy']); 
    if (have_posts()) : while (have_posts()) : the_post(); ?> 

In case anyone's wondering I've tried using a new or standard query, but it seems to break some of woocommerce's functionality.

So basically Id like to modify the above query to show all posts...

any ideas? thanks!!

1

This code:

$term = get_term_by( 'slug', get_query_var($wp_query->query_vars['taxonomy']), $wp_query->query_vars['taxonomy']); 

... just fetches the term data for the currently queried term, it's not altering the query in any way.

To alter the query for your taxonomy term archives, you want to use the pre_get_posts action. Altering the query in the template just creates a new query, overwriting the original, as the main query for all pages happens before the template is loaded. This code would go in your theme's functions.php or a custom plugin:

function wpa_alter_taxonomy_query( $query ) {
    if ( is_tax( 'your-taxonomy' ) && is_main_query() )
        $query->set( 'posts_per_page', -1 );
}
add_action( 'pre_get_posts', 'wpa_alter_taxonomy_query' );

just change 'your-taxonomy' to the name of your taxonomy.

| improve this answer | |

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.