T
T
tseries Task2019-01-19 09:44:57
Taxonomy
tseries Task, 2019-01-19 09:44:57

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'
    );

Outputting a single entry also works:
$args = array(
       'post_type' => 'services',
      'p' => 41396 
);

but the output by category id does not work:
$args = array(
        'cat' => '1093',

   // 'post_type' => 'services', //пробовал добавлять postype разный
       //через tax_query тоже не работает
         
);

Entirely, just in case:
$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();

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
poshta3005, 2019-01-19
@poshta3005

'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 question

Ask a Question

731 491 924 answers to any question