[wp-trac] [WordPress Trac] #33827: WP Query: Custom Post Types and Categories

WordPress Trac noreply at wordpress.org
Fri Sep 11 12:11:32 UTC 2015


#33827: WP Query: Custom Post Types and Categories
--------------------------+-----------------------------
 Reporter:  atomicjack    |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  4.3
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Hi,

 It seems that you cannot use a custom post type's category as a filter
 during a WP Query, see here:


 {{{
 <?php
 $the_query = new
 WP_Query('cat=4&taxonomy=product_categories&posts_per_page=-1&post_type=products&status=publish'
 );

                                                 if (
 $the_query->have_posts() ) {
                                                         echo '<ul>';
                                                         while (
 $the_query->have_posts() ) {
 $the_query->the_post(); ?>
                                                                 <?php
 $queried_objects = get_the_terms($post->ID, 'product_category');
                                                                 foreach (
 $queried_objects as $queried_object ) {
 $current_term = $queried_object->term_id;
                                                                 }
                                                                 ?>
 }}}

 Whenever a category ID is placed in to the query, no results will be
 returned, even though there are items in there.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/33827>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list