Skip to content

Instantly share code, notes, and snippets.

@robertito13
Last active April 20, 2018 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertito13/3d722251cecad361ed76bd4065bc1b85 to your computer and use it in GitHub Desktop.
Save robertito13/3d722251cecad361ed76bd4065bc1b85 to your computer and use it in GitHub Desktop.
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