• I believe I would have to ad or change something (probably in the array) in this bit of code?

    `if($my_post_type == CUSTOM_POST_TYPE1){
    $my_post_cat = ‘placecategory’;
    }else{
    $my_post_cat = ‘eventcategory’;
    }

    $args=array($my_post_cat => $category,
    ‘post_type’ => $my_post_type,
    ‘posts_per_page’ => $number,
    ‘ignore_sticky_posts’=> 1);
    $my_query = null;
    $my_query = new WP_Query($args);

    if( $my_query->have_posts() ) { ?>
    <div id=”loop” class=”list clear”>
    <?php if($title){ ?> ……..`

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Yes, $my_post_cat => $category will not work. To include posts in $my_post_cat, change to category_name => $my_post_cat . Note the value assigned to $my_post_cat should be the category slug, not the name. Any other variation will require category ID instead of slug, which you can get from get_cat_ID(‘category_name’). Note this time we need the name, not the slug.

    So to show posts that are not in a particular category ID, use category_not_in => array( $cat_id ) where $cat_id is assigned the ID returned from get_cat_ID(). Also note we must pass an array argument even if we only have one value to supply.

Viewing 1 replies (of 1 total)
  • The topic ‘Excluding Category in Custom Post Type…’ is closed to new replies.