Last active
April 20, 2018 16:12
-
-
Save robertito13/3d722251cecad361ed76bd4065bc1b85 to your computer and use it in GitHub Desktop.
Evitar los post duplicados al utilizar múltiples loops en WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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