Let's say that I have a post that I only want to be shown in the page of the category that it belongs to. The problem is that this post is also visible in the latest posts page.

Is there a way to hide this post from the latest post page and show it only in the page of the category of the post?

  • How are you displaying posts on latest post page? Commented Apr 2, 2013 at 12:07
  • @VinodDalvi: I only have configured ad the wp-admin interface in the Reading Settings that a page that I created show the posts (This page is not the front page of the blog). Commented Apr 2, 2013 at 12:09
  • Which theme are you using? Commented Apr 2, 2013 at 12:17
  • I'm using the Chateau Theme, but if you tell me that I need to change the theme, this can be done. The main concern is that it must work in the Minileven mobile theme, because I have many users that access the blog from a mobile device. Commented Apr 2, 2013 at 12:31

3 Answers 3

function exclude_single_posts_home($query) {
  if ($query->is_home() && $query->is_main_query() && !is_admin()) {
    $query->set('post__not_in', array(post-id));

add_action('pre_get_posts', 'exclude_single_posts_home');

Source: pre_get_posts


Since you're using the core "Page for Posts" settings, you should be able to use the awesome pre_get_posts action to remove the specific ID you want to exclude.

This should work in your functions.php file or /mu-plugins/ plugin:

wpse94273_hide_post( $query ) {
    // only remove post ID from page_for_posts and in the main query
    if( $query->is_home() && $query->is_main_query() ) {
        // remove specific page ID from query
        query->set( 'post__not_in', array( {your post id} ) );
add_action( 'pre_get_posts', 'wpse_94273_hide_post' );

Replace "{your post id}" with the ID of the post you want to exclude. It's an array, so you can enter multiple IDs separated by commas if desired.

If the post ID changes, then you'd need to setup some kind of option using the Settings API to store the ID you want to exclude.


Your question is hard to understand.. Do you mean a specific post or somthing automatic? if you mean a specific post and If you are using wp_query / query posts to loop for recent posts you can add this parameter.

'post__not_in' => array($postId)

Example query:

$relatedargs = array(
    'post__not_in'      => array($postId) // THIS IS THE LINE
$the_query = new WP_Query( $relatedargs );

// The Loop
if( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) : $the_query->the_post();



Hope this helps ;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.