Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Evitar los post duplicados al utilizar múltiples loops en WordPress
<?php
class WP_Deduplicator {
private static $published = array();
public static function add( $post = null ) {
$post = get_post( $post );
if ( !in_array( $post->ID, self::$published ) )
array_push( self::$published, $post->ID );
}
public static function get() {
return self::$published;
}
}
$query = new WP_Query([
'post__not_in': WP_Deduplicator::get()
// ...
]);
while ( $query->have_posts() ) {
$query->the_post();
WP_Deduplicator::add();
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.