0

I have two areas where I fetch the most recent entries. In the first area, I want to get the first 10 posts. In the second area, I want to fetch the posts starting at post number 11....

I have this:

<?php

$args = array( 'numberposts' => '10' );
$recent_posts = wp_get_recent_posts($args);
$featured_posts = themename_get_featured_posts();
if(!empty($featured_posts) && is_array($featured_posts))
{
    $query_arr = array(
        'post__not_in' => $featured_posts, $recent_posts,
        'paged' => $paged,
        'suppress_filters' => false,
    );
    query_posts($query_arr);
}

$key = 11;
if (have_posts()) : while (have_posts()) : the_post();
    $image_thumb = '';
    $key++;
    $image_id = get_post_thumbnail_id(get_the_ID());
?>

But whatever I do (even if I'd remove the first if statement) I keep seeing the same posts in every area...

How can I get this to work?

1

Looking at the pagination parameters I see two possibilities: Either use offset or paged.

$args = array(
    'posts_per_page' => 10,
    'offset' => 10,
);

should work just as well as

$args = array(
    'posts_per_page' => 10,
    'paged' => 2,
);
  • Nope. I also don't see how that should work. I don't need pagination.... I just want to start with post number 11, without pagination or so. It doesn't work. Behaviour stays the exact same. – Siyah Sep 20 '17 at 11:53
  • Only because you don't actually display different pages, does not mean you do not want pagination. Because it is exactly what you want ;) This is the standard way, you would go about this. Can you edit (in your question), how you used this in your code? – kero Sep 20 '17 at 12:17
1

I solved it myself. What I did, is adding this:

                    $loop = new WP_Query(array(
                        'offset' => 20,   
                    ));

And then changing:

if (have_posts()) : while (have_posts()) : the_post();

into:

if ($loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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