Answer the question
In order to leave comments, you need to log in
How to correctly display posts of the selected taxonomy category in taxonomy.php?
Good afternoon !
For an arbitrary post type, I created an aspect taxonomy, created several categories with it, in order to refer posts to them.
I output at the moment like this:
<?php
global $query_string;
$posts = query_posts($query_string.'&posts_per_page=9'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
everything works, but we are affecting the main Wordpress loop ((
I'm trying to display this:
$taxonomy = get_query_var('taxonomy');
$args = array('taxonomy' => $taxonomy, 'posts_per_page' => 9, 'paged ' => $paged );
$querys = new WP_Query( $args );
while ( $querys->
but something doesn't work, what do you say?
Answer the question
In order to leave comments, you need to log in
It is somewhat difficult to judge, I did not see how everything is arranged with you. But as far as I remember, I wrote the following arguments:
https://codex.wordpress.org/Class_Reference/WP_Que...
and already threw my taxonomy into tax_query.
For my product taxonomy, I created categories, conditionally (Beans, Greens, Parsley, Tomatoes, Cucumbers, Cabbage, Beets), displayed them all on the template page, when I need to see the posts of a category, I click on it and the template is loaded (one for all categories) taxonomy.php
How I display posts in it I wrote above
It turns out that I need to somehow get it in taxonomy.php (into the category variable I clicked on) 'terms' => 'Variable ', 'terms' - as I understand it, this is my category , but how is it further understood
$args = array(
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'product',
'field' => 'slug',
'terms'=> 'Variable (my chosen category)',
),
),
);
$query = new WP_Query( $args );
Why don't you like the native Template Hierarchy, which does everything for you "magically"?
https://developer.wordpress.org/themes/template-fi...
Why produce additional requests? You always need to follow this path:
1. Is it possible to use a ready-made native template that will form the correct main query itself?
2. Is it possible to change the main request through the pre_get_posts hook?
3. Is it possible to achieve the desired result with an additional arbitrary WP_Query or get_posts?
In most cases, step 1 or 2 is enough. Step 3 is used in special cases - you need an extra loop, you need to get a couple of "related" posts, and so on.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question