Different Queries Return Same Results [closed]

EDIT: After fiddling with the loop a bit, it somehow corrected itself. At the end of the day the code remains the same, only now it’s working.


http://sct.io/tt95p4 – development site. Scroll down below the slider to see the two areas in question (Featured Articles and Latest News)

I have two sections in one template that are using different queries to pull post excerpts and featured images. The odd behavior here is that even though I have the two separate queries, both are returning the same result.

In my template page I have:

<?php
global $post;
$myposts = get_posts('numberposts=2&offset=0&category=23');
foreach($myposts as $post) :
setup_postdata($post);
?>
...
<?php endforeach; ?>

and the second block:

<?php
global $post;
$myposts = get_posts('numberposts=4&offset=0&category=-23');
foreach($myposts as $post) :
setup_postdata($post);
?>
...
<?php endforeach; ?>

So basically wanting the Featured Articles to display the 2 most recent posts from category “23”, and the second block should display the 4 most recent articles not in category “23”.

For some reason both blocks are returning the posts from category 23.

I am hoping this is a simple fix and I am just missing some small detail.

Thanks in advance!

1 Answer
1

Use wp_reset_postdata() this may accomplish your requirement

Leave a Comment