Display posts belonging in 1 category as well as others
-
Hi,
I have a custom post type “portfolio” and all portfolio items can belong to one or more categories.
I wish to display all portfolio items that belong to a specific category but the portfolio items can belong to other categories as well.
Currently, the page displays all portfolio items and there are two instances where the portfolio items are identified:
Query 1:
<?php $catorg = get_post_meta($post->ID, 'portfolio_categories', TRUE); ?> <?php $cat = implode(',', $catorg); ?> <div class="twelve columns"> <h4><?php _e( 'Filter', THB_THEME_NAME ); ?></h4> <ul class="filters hide-for-small"> <li><a href="#" data-filter="*" class="active"><?php _e( 'show all', THB_THEME_NAME ); ?></a></li> <?php $portfolio_categories = get_categories(array('taxonomy'=>'project-category', 'include' => $cat)); foreach($portfolio_categories as $portfolio_category) { $args = array( 'post_type' => 'portfolio', 'post_status' => 'published', 'project-category' => $portfolio_category->slug, 'numberposts' => -1 );
Query 2:
<?php $args = array( 'post_type' => 'portfolio', 'orderby'=>'menu_order', 'order' => 'ASC', 'posts_per_page' => '-1', 'tax_query' => array( array( 'taxonomy' => 'project-category', 'field' => 'id', 'terms' => $catorg, 'operator' => 'IN' ) ) // end of tax_query ); ?> <?php $query = new WP_Query($args); ?> <?php if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); $terms = get_the_terms( get_the_ID(), 'project-category' ); $type = get_post_meta($post->ID, 'portfolio_type', true);
Essentially, how do I add a condition to the $args or elsewhere that ensures that the posts returned belong to a specific category using the category ID but also can belong to other categories.
Thank you in advance for your time.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Display posts belonging in 1 category as well as others’ is closed to new replies.