issue to get the custom post type based on custom post type category in wordpress?

I have created the custom post type article and category “Education”.
I wanna to get all the posts of category “Education”, i.e post type article but when I pass category id in query then it does not return any post. If I remove the category id from the query then it returns all the posts of type article.

How can I get the posts based on category that I have created for custom post article.
I am using the following code.

   $args = array(
  'post_type' => 'article',
  'orderby' => 'date',
  'order' => 'ASC',
  'post_status' => 'publish',
  'cat' => '18'


   );
  $query = new WP_Query($args);
  print_r($query);

Related posts

Leave a Reply

1 comment

  1. Try this,

    $args = array(
      'post_type' => 'article',
      'orderby' => 'date',
      'order' => 'ASC',
      'post_status' => 'publish',
      'cat' => 18
    
    
       );
      $query = new WP_Query($args);
      print_r($query);
    

    The problem is you added quotes for ‘cat’ => ’18’, this should be ‘cat’ => 18..

    Hope this works