I know this topic has been covered multiple times before, but I've tried every tutorial I've found online and haven't been able to figure it out.

I'm using the free NewsMojo theme (http://fthemes.com/newsmojo-free-wordpress-theme/) on my blog (http://eldoradofrontier.com/) and would like to have the posts appearing in the "featured" carousel not also appear in the main feed below it. I don't want to use any category filtering, because I expect my site to have too many new posts for it to make sense to have to go back and remove old posts from the featured carousel.

I don't know much about PHP, but I tried the $do_not_duplicate trick mentioned in the codex (it won't let me post the link because I'm new) without any success.

As far as I can tell, these are the two loops on my homepage:

One, in the file template.php in the folders "featuredposts":

            $featuredposts_source = $this->theme->get_option('featuredposts_source');
            $featuredposts_moreoptions = $this->theme->get_option('featuredposts_moreoptions');

            $featuredposts_query = false;

            if($featuredposts_source == 'category') {
                if($this->theme->display('featuredposts_source_category')) {
                    $featuredposts_query = 'posts_per_page=' . $this->theme->get_option('featuredposts_source_category_num') . '&cat=' . $this->theme->get_option('featuredposts_source_category');
            } elseif($featuredposts_source == 'posts') {
                if($this->theme->display('featuredposts_source_posts')) {
                    $featuredposts_query = array('post__in'=> explode(',', trim($this->theme->get_option('featuredposts_source_posts'))), 'post_type'=>'post');
            } elseif($featuredposts_source == 'pages') {
                if($this->theme->display('featuredposts_source_pages')) {
                    $featuredposts_query = array('post__in'=> explode(',', trim($this->theme->get_option('featuredposts_source_pages'))), 'post_type'=>'page');

            if($featuredposts_query) {
                $featuredposts_excerpt_length = $this->theme->get_option('featuredposts_excerpt_length');
                if (have_posts()) : while (have_posts()) : the_post(); 

And the next, in the file loop.php:

global $theme;
if (have_posts()) : while (have_posts()) : the_post();

I think I need to create an array with the post IDs in the first loop, then tell the second loop to ignore those posts ... right? But how do I do that?

Thanks in advance for the help, and sorry for the noob question! -Cody

  • Yes you need to create an array in the first loop and check against it in the second. Not sure where is the difficulty that you run into? Dec 1, 2013 at 9:28

1 Answer 1


As usual with multiple loops, one of which is main loop, the issue is messy.

What it looks like is happening:

  1. Secondary loop runs and deals with some posts.
  2. Main loop runs and deals with some posts.

What is actually happening:

  1. WordPress core is loaded.
  2. Posts are queried for main loop.
  3. Template file is decided on and loaded.
  4. Secondary loop runs and deals with some posts.
  5. Main loop runs and outputs those posts queried way above in the process.

To cleanly accomplish what you want would take:

  • completely moving that featured logic out of template
  • using it to override what is queried for main loop on pre_get_posts hook (massive topic by itself, search around the site)
  • storing that info and using it way later to run custom loop in template

It's not overly complicated, but very menial and prone to errors (as in I wouldn't even try to modify this going by snippets without hands on access and testing on actual theme and site).

  • Thanks for the answer, @Rarst. I'm still very new to PHP, so that helps a lot. I'll investigate the pre_get_posts method.
    – cody
    Dec 1, 2013 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.