A
A
Alexey Verkhovtsev2018-03-27 18:16:32
WordPress
Alexey Verkhovtsev, 2018-03-27 18:16:32

How to set LIMIT 3, 6 for WP_Query fetch?

Hello. I want to load records on Ajax when a button is pressed. As a result, the function looks like this

$startFrom = $_POST['startFrom'];
    $postsPerPage = $_POST['postsPerPage'];
    $latest_posts = new WP_Query(
        [
            'post_type' => 'post',
            'posts_per_page' => $postsPerPage, //6
            'offset' => $startFrom //3
        ]
    );

this is what the request looks like
[request] => SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts  WHERE 1=1  AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.post_status = 'private')  ORDER BY wp_posts.post_date DESC LIMIT 3, 6

But 6 news items are returned instead of 3, what should I do? What's the trouble

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
E, 2018-03-27
@aylo

posts_per_page = 6
you explicitly stated it yourself, write there 3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question