php – Three different queries on same page
I’m trying to display three different queries with same post type, taxonomy, post__in argument and different taxonomy term for each of them. Thing is, that first query return posts without a problem, but other two not at all.
This is the first time i have encountered something like that and i’m completely at loss here.
The idea is:
To filter each query by specific terms from custom taxonomy and by list of specified ID’s from array.
Things i have tried:
- switching to meta_query instead of “post__in” argument,
- giving slugs to tax_query field instead of ID’s
Additional infos:
- The $tm_specs returns serialized array, so it’s the proper source
- If i just remove first query whatsoever, then the other two still not renders.
The weird thing is that if i remove either tax_query
or post__in
from the second or third query then it renders properly.
I would really appreciate any help in that matter.
The code:
$ts_args = array(
'post_type' => 'specjalizacja',
'posts_per_page' => -1,
'post__in' => $tm_specs,
'tax_query' => array(
array(
'taxonomy' => 'kategoria',
'field' => 'ID',
'terms' => 2,
),
),
);
$ts_loop = new WP_Query($ts_args);
$fy_args = array(
'post_type' => 'specjalizacja',
'posts_per_page' => -1,
'post__in' => $tm_specs,
'tax_query' => array(
array(
'taxonomy' => 'kategoria',
'field' => 'ID',
'terms' => 3,
),
),
);
$fy_loop = new WP_Query($fy_args);
$dtb_args = array(
'post_type' => 'specjalizacja',
'posts_per_page' => -1,
'post__in' => $tm_specs,
'tax_query' => array(
array(
'taxonomy' => 'kategoria',
'field' => 'ID',
'terms' => 4,
),
),
);
$dtb_loop = new WP_Query($dtb_args);
<?php while ( $ts_loop->have_posts() ) {
$ts_loop->the_post();
echo '<a href="'.get_the_permalink().'" class="bordered-btn-big"><span>'.get_the_title().'</span></a>';
} wp_reset_postdata(); ?>
<?php while ( $fy_loop->have_posts() ) {
$fy_loop->the_post();
echo '<li class="bordered-btn"><a href="'.get_the_permalink().'"><span>'.get_the_title().'</span></a></li>';
} wp_reset_postdata(); ?>
<?php while ( $dtb_loop->have_posts() ) {
$dtb_loop->the_post();
echo '<li class="bordered-btn"><a href="'.get_the_permalink().'"><span>'.get_the_title().'</span></a></li>';
} wp_reset_postdata(); ?>
Leave an answer