简体   繁体   中英

Wordpress WP_Query tricks to avoid duplicated posts

I'd like to implement infinite posts functionality using WP_Query function. There are two divs in page.

When you scroll down to the bottom every div loads more its own posts like newest or its own categories posts.

But I don't want to load duplicated posts (ie, if you load newest posts in div1, while div 2 load posts by category, some posts could be loaded in two divs).

How can I avoid this?

Any help would be appreciated.

You need to send data about the loaded divs in ajax request on scroll. On php side you need to do something like this:

$exclude_ids = '1,2,3';
$query = new WP_Query( array( 'post__not_in' => array( $exclude_ids ) ) );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM