Grow your CSS skills. Land your dream job.

Excluding Category in Custom Post Type…

  • # March 13, 2013 at 7:48 am

    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() ) { ?>

    < ?php if($title){ ?> ……..
    # March 13, 2013 at 10:17 am

    is the “placecategory” and “eventcategory” the slug names for your categories?

    If so try replacing

    $my_post_cat => $category

    With

    ‘category_name’ => $my_post_cat

    # March 14, 2013 at 8:06 am

    Hi esquivelia,

    If you want to **exclude** a category from the loop you would use something like the following instead

    ‘cat’ => -13

    Where 13 is the category id.

    To get the category id from the category slug do something like this

    < ?php
    $catObj = get_category_by_slug($my_post_cat);
    $catID = $catObj->term_id;
    ?>

    So then the parameter for WP_Query would become:

    ‘cat’ => $catID

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".