get_posts with excluding category
-
Hi all.
The version of my WordPress is 3.5.1
I modified my front-page file.
This code gets the most recent post from the loop.
I want to exclude a category.
The id of the category is ‘6’.<?php $args = array( 'numberposts' => 1, 'exclude' => '6' ); $lastposts = get_posts( $args ); foreach($lastposts as $post) : setup_postdata($post); ?> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <?php the_content(); ?> <?php endforeach; ?>I also tried
$args = array( 'numberposts' => 1, 'cat => -6' );But it does not work: in the home page show all, including the post of the excluded category.
I read the documentation and this old topic, but these pages didn’t help me
I wonder where I am going wrong.
Thank you
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘get_posts with excluding category’ is closed to new replies.