Last active
May 21, 2019 12:17
-
-
Save OscarAbadFolgueira/9da651fe8f2b98332125f23d076e1cf6 to your computer and use it in GitHub Desktop.
WP_Query: Excluir el post actual
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 | |
// snippet para exluir el post actual de la consulta o loop de WordPress | |
// author: Oscar Abad Folgueira. @oabadfol | |
// author-url: http://www.oscarabadfolgueira.com | |
$args = array ( | |
'post_type' => array( 'evento' ), | |
'posts_per_page' => '3', | |
'post__not_in' => array(get_the_ID()), // Excluir el post actual | |
); | |
$query = new WP_Query( $args ); | |
if ( $query->have_posts() ) : | |
while ( $query->have_posts() ) : $query->the_post(); | |
// código para el tratamiento de los datos en el loop | |
the_title(); // Por ejemplo... | |
endwhile; | |
endif; | |
wp_reset_postdata(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment