Excluir la Entrada Actual del Bucle de Entradas Recientes
¿Cuál sería la mejor manera de excluir la entrada actual que estoy visualizando de esta consulta de entradas recientes? ¡Gracias!
<?php
// Obtener la variable global post
global $post;
if (in_category('top-lists')) {
$myposts2 = get_posts('numberposts=5&offset=0&category=7&post__not_in=' . array($post->ID));
}
else if (in_category('playlists') || in_category('playlistall')) {
$myposts2 = get_posts('numberposts=5&offset=0&category=6,37&post__not_in=' . array($post->ID));
}
else if (in_category('news') || in_category('news')) {
$myposts2 = get_posts('numberposts=5&offset=0&category=95&post__not_in=' . array($post->ID));
}
else {
$myposts2 = get_posts('numberposts=5&offset=0&category=-6,-7,-37,-95,-177&post__not_in=' . array($post->ID));
}
foreach($myposts2 as $post) :
?>
@kaiser y Brian - Gracias por responderme, puse el código pero estoy obteniendo un error de map_array ----
Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/sitemain/public_html/wp-includes/query.php on line 1709
Warning: implode() [function.implode]: Invalid arguments passed in /home/sitemain/public_html/wp-includes/query.php on line 1709

Prueba con la última edición. Introduce tus argumentos en un array.

Actualmente estoy usando esto <?php $catquery = new WP_Query( 'cat=1&posts_per_page=5' ); ?>
. ¿Cómo implemento el tuyo en el mío? ¡Gracias!

Añade esto a tus $args
'post__not_in' => array( get_the_ID() )
De esta manera no tendrás que lidiar con obtener el ID del post actual y potencialmente evitarás errores al obtener tu ID. La función get_the_ID() simplemente obtiene el ID por ti para que no tengas que preocuparte o hacer nada adicional.

Agrega el siguiente código en el archivo functions.php del tema activo:
function be_exclude_current_post( $args ) {
if( is_singular() && !isset( $args['post__in'] ) )
$args['post__not_in'] = array( get_the_ID() );
return $args;
}
add_filter( 'widget_posts_args', 'be_exclude_current_post' );
