WordPress.org

Ready to get started?Download WordPress

Forums

Show Specific Category of Custom Post Type (4 posts)

  1. Chris
    Member
    Posted 2 years ago #

    Hey All

    I have been searching and searching and cannot seem to find a working answer. I am trying to show a specific category of a custom post type. Here is to code I am working with:

    <?php $args = array( 'post_type' => 'roster', 'posts_per_page' => 30, 'orderby' => desc );
    		$loop = new WP_Query( $args );
    		while ( $loop->have_posts() ) : $loop->the_post(); ?>
    		<h2 class="member-name"><?php the_title(); ?></h2>
        <div class="member-description">
    		<?php the_post_thumbnail('thumbnail');?>
    		<?php the_content(); ?>
        </div>
    		<?php endwhile; ?>

    What do I need to insert to call the specific category or to filter out the other categories?

    Thanks!

  2. adrian7
    Member
    Posted 2 years ago #

    Something like this:

    $args =	array('showposts'=>25, 'category'=>'mycat', 'post_type'=>'mytype');
    $query = new WP_Query($args);
  3. Chris
    Member
    Posted 2 years ago #

    Hmmmm.... thank you for your help. It does not seem to be working however. Here is what I am now trying but it just shows the posts from all the cateogries:

    <?php $args =	array('showposts'=>25, 'category' => 'former-members' ,'post_type'=>'roster');
    $query = new WP_Query($args);
    		while ( $query->have_posts() ) : $query->the_post(); ?>
    		<h2 class="member-name"><?php the_title(); ?></h2>
           <div class="member-description">
    		<?php the_post_thumbnail('thumbnail');?>
    		<?php the_content(); ?>
        </div>
    
    		<?php endwhile; ?>

    And suggestions?

  4. adrian7
    Member
    Posted 2 years ago #

    So if you need to filter out a specific term, from taxonomy also add tax query like:

    tax_query=>array('field'=>'id', 'terms'=>'12,16', 'operator'=>'IN')

    but if tour taxonomy is the built-in category taxonomy just add:

    category__in=>array(12,16)

Topic Closed

This topic has been closed to new replies.

About this Topic