也许像这样的方法行得通?
// Assuming $posts = new WP_Query( $args );
$post_to_remove = 123;
// If using post objects
foreach ( $posts->posts as $i => $post ) {
if ( $post_to_remove == $post->ID ) {
unset( $posts->posts[$i] );
break; // no need to continue the loop as the post has been found
}
}
// If only IDs were queried
foreach ( $posts->posts as $i => $post_id ) {
if ( $post_to_remove == $post_id ) {
unset( $posts->posts[$i] );
break; // no need to continue the loop as the post has been found
}
}
// do your rendering while/for/foreach loop after sorting
EDIT 我想,你也可以跳过循环中的帖子。
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php if ( $post_to_remove == get_the_id() ) { continue; } ?>
<?php endwhile; ?>
<?php // Navigation ?>
<?php else : ?>
<?php // No Posts Found ?>
<?php endif; ?>