Skip to content

Instantly share code, notes, and snippets.

@OscarAbadFolgueira
Last active May 21, 2019 12:17
Show Gist options
  • Save OscarAbadFolgueira/9da651fe8f2b98332125f23d076e1cf6 to your computer and use it in GitHub Desktop.
Save OscarAbadFolgueira/9da651fe8f2b98332125f23d076e1cf6 to your computer and use it in GitHub Desktop.
WP_Query: Excluir el post actual
<?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