WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Excluding multiple categories using $exclude[] tree (2 posts)

  1. Waqas
    Member
    Posted 1 year ago #

    hello, I'm having a little problem. I've search the whole internet

    here is my code

    <?php
    		$exclude = get_option( 'sticky_posts' );
    		$exclude[] = $category[0]->cat_ID;
    		$loop = new WP_Query(
    			array(
    				'category__not_in' => $exclude,
    				) );
    		$m = 0;
    		while ( $loop->have_posts() ) : $loop->the_post(); $m++;
    		?>

    Im using this code to get recent posts in single.php currently I'm eliminating the recent posts of from "Current Category" being watch in single.php

    but I want to exclude another category. can anyone help me too exclude multiple categories.

  2. Waqas
    Member
    Posted 1 year ago #

    just solved my problem without any help, the full working code is

    <?php $category = get_the_category(); ?>
        <?php
        $exclude = get_option( 'sticky_posts' );
        $exclude[] = $category[0]->cat_ID;
        $loop = new WP_Query(
            array(
                'category__not_in' => $exclude,
                'cat'=> -36,
                ) );
        $m = 0;
        while ( $loop->have_posts() ) : $loop->the_post(); $m++;
        ?>
        my content goes here
        <?php endwhile; ?>
        <?php wp_reset_query(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic