Answer the question
In order to leave comments, you need to log in
How to display posts by category id for custom taxonomy?
Good afternoon. I ran into a question about displaying records by subcategory id from custom categories.
For some reason, it does not display posts from the category if there is a condition.
this is how it works, displays all posts from all categories.
$args = array(
'post_type' => 'services'
);
$args = array(
'post_type' => 'services',
'p' => 41396
);
$args = array(
'cat' => '1093',
// 'post_type' => 'services', //пробовал добавлять postype разный
//через tax_query тоже не работает
);
$args = array(
'cat' => '1093'
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>' . get_the_title() .'id='.get_the_ID(). '</li>';
}
} else {
echo '<li>ничего</li>';
}
wp_reset_postdata();
Answer the question
In order to leave comments, you need to log in
'cat' => '1093'
What confuses me is that the category has a number in quotes.
Perhaps the query perceives it not as a number, but as a text variable? And that's exactly the problem?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question