Viewing 2 replies - 1 through 2 (of 2 total)
  • I found a way to exclude categories, it’s kind of a work around but it works. First I run a counter. Then I set the limit a lot higher than the limit i want (40), then i put in a continue statement if it’s the caregory i want to exclude. If the counter is at the limit i really want(10), i put in the break statement. It works perfectly.

    Here’s my code:

    <!--most populair posts-->
    <?php $count = 1; //setting the counter
    
    $posts = wmp_get_popular( array( 'limit' => 40, 'post_type' => 'post', 'range' => 'monthly' ) ); //setting a higher limit
    global $post;
    if ( count( $posts ) > 0 ): foreach ( $posts as $post ):
    setup_postdata( $post );
    
    if ( in_category( 'exclude_this_category' )) { continue; } ?><!--exclude the unwanted category-->
    
    <a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a>
    
    <?php $count++; //add 1 to the counter
    if ($count == 11) {break;} //break when i have run the loop 10 times
    endforeach; endif;?>
    <!--most populair posts-->

    Hope this helps

    Thread Starter andrereitz

    (@andrereitz)

    Great, thanks for sharing!

    I was doing this but manually, I was increasing the posts in widget in case some of not showing category take espace ??!

    I’ll definitely try this!
    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exclude one or more category from results’ is closed to new replies.