WordPress.org

Support

Support » WP-Advanced » Excluding a specific category in a photo gallery

Excluding a specific category in a photo gallery

Viewing 3 replies - 1 through 3 (of 3 total)
  • $cats = get_terms(‘portfolio_cats) assigns the variable $cats with an array of all of the term objects of the portfolio_cats custom taxonomy. So once you do the loop (foreach ($cats as $cat )), the variable $cat will be assigned, one at a time, with the different term objects. That term object’s values are obtained by referencing the object’s properties, so echo $cat->name will echo the name property of the current term object. So in order to skip some of the custom taxonomy terms, you could, within the foreach loop, do something like:

    if ($cat->name == 'this_term_should_be_skipped')
    {
         continue;
    }
    else
    {
         // the code that is already in the foreach loop...
    }

    Hi,
    I need to exclude specific category posts from this loop but same getting all posts of all categories..
    This is my code:

    <?php
    				$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    				$wp_query = new WP_Query('posts_per_page='.get_theme_mod('home_postnum').'&paged=' . $paged);
    				if (have_posts()) {
    					while (have_posts()) : the_post();
    						global $post;
    						include(TEMPLATEPATH. '/includes/loop.php');
    					endwhile;
    				} else {
    					include(TEMPLATEPATH. '/includes/not-found.php');
    				}
    
    				wp_reset_query();
    			?>

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Please help me regarding this Issue..
    Thanks
    —————

    try something like this

    $args = array(
    'category__not_in' => some_id
    'more_args' => ''
    );
    
    $loop = new WP_QUERY($args)
    
    while($loop->have_posts()) : $loop->the_post() ;
    // your content for the loop
    endwhile;
    wp_reset_query();

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Also check out the codex here https://codex.wordpress.org/Class_Reference/WP_Query

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Excluding a specific category in a photo gallery’ is closed to new replies.