Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8563713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:01:27+00:00 2026-06-11T17:01:27+00:00

I have a wordpress page which has two loops like so… <?php global $post;

  • 0

I have a wordpress page which has two loops like so…

<?php 
global $post;
$args = array(
    'showposts'        => 1,
    'category_name'    => 'videos',
    'meta_key'         => 'feature-image',
);

$myposts = get_posts($args);  
foreach( $myposts as $post ) :  setup_postdata($post);
$exclude_featured = $post->ID;
?>
<span class="featured">
<?php the_title(); ?>
</span>
<?php endforeach; ?>

<?php while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>

Now I need to use $exclude_featured in my second loop some how to exclude that post from that loop. I’ve tried a few implementations but none of them have worked. I have tried adding the following above the while statement for the second loop…

global $query_string;
query_posts( $query_string . '&exclude='.$exclude_featured );

and this…

global $wp_query;
$args = array_merge( $wp_query->query_vars, array( 'exclude' => $exclude_featured ) );
query_posts( $args );

.. and have had no luck. I’ve noticed that by using either of these two snippets they also render my pre_get_posts function which sets the number of posts to display useless.

Any help would be appreciated

EDIT:

I’ve tried adding the following lines before the while statement on the second loop..

global $wp_query;
$args = array_merge( $wp_query->query_vars, array( 'post__not_in' => $exclude_featured ) );
query_posts( $args );

However I still have not had any success, it brings up the following error:

Warning: array_map() [function.array-map]: Argument #2 should be an
array in
/home/myuser/public_html/mysitedirectory/wp-includes/query.php on line
2162

Warning: implode() [function.implode]: Invalid arguments passed in
/home/myuser/public_html/mysitedirectory/wp-includes/query.php on line
2162

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:01:29+00:00Added an answer on June 11, 2026 at 5:01 pm

    You could substitute your last three lines with these:

    <?php
    while ( have_posts() ) : the_post();
    if ( $exclude_featured == get_the_ID() )
        continue;
    
    the_title();
    endwhile;
    ?>
    

    continue is used within looping structures to skip the rest of the current loop iteration and continue execution at the condition evaluation and then the beginning of the next iteration.

    This will, however, result in that you’re having one less post to display. If you’d like to keep your post count exactly the same, you would need to exclude the post in the query. The query in the question is pretty close to being correct, but post__not_in has to be an array, and not an integer. All you need to do is wrap your $exclude_featured in an array, and your query should work.

    Your query should look like this:

    global $wp_query;
    $args = array_merge(
        $wp_query->query_vars,
        array(
            'post__not_in' => array(
                $exclude_featured
            )
        )
    );
    query_posts( $args );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WordPress site which have 4 pages with one page is a
I have a weird bug in Chrome which affects a page in Wordpress. I
I have a wordpress theme in which i have to create a page that
I have a wordpress page (Sofa QandA). I want to change the color of
I have a wordpress-generated page where I need some posts (in a specific category)
I have wordpress a site with a customized login page, the problem is when
I have 3 google +1 buttons in the same wordpress page. But one of
I have a custom search engine on a non-wordpress page. This search engine searches
what I have: a google search form (displayed on all pages) a wordpress page
I am displaying the iframe in wordpress page template. In iframe src i have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.