• Resolved muhammadwaqas

    (@muhammadwaqas)


    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.

Viewing 1 replies (of 1 total)
  • Thread Starter muhammadwaqas

    (@muhammadwaqas)

    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(); ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Excluding multiple categories using $exclude[] tree’ is closed to new replies.