1

Ex: In my field "POSTS" I have 10 posts. Let's say I do not want to display the post "8", which has the ID (looking in the URL) "155".

How can I do to not display this post on my home page? I want to display it only when I click on the category.

Looking at the documentation and Googling I saw that you can not display the entire category. Just use the cat and argument be negative the category ID ($args = array ( 'cat' => ID_CATEGORY));.

But it does hide the whole category. I want to hide only 1 post (home) in this category.

I also found this code:

function exclude_single_posts_home($query) {
//Caso esteja na home  
   if ($query->is_home() && $query->is_main_query()) {
    //Não exiba estes posts
$query->set('post__not_in', array(187,174,166));   } }

add_action('pre_get_posts', 'exclude_single_posts_home');

As I understand it, he takes the post ID and does not display it is in case home. Well, I did not catch: /

Anyway,

How do I prevent certain post of home by ID? So he only appears when I click on the category.

obs: My home is being displayed in page.php

0

This has worked for me. Can you try it and replace the excluded ID by the id of post you want to exclude.

add_filter( 'pre_get_posts', 'exclude_specific_post_id' );
function exclude_specific_post_id( $query ) {

    if ( $query->is_main_query() ) {
        $query->set( 'post__not_in', array( 'YOUR_EXCLUDED_POST_ID_HERE' ) );
    }
}
  • This code exclude the post in my Dashboard "Posts". In my site the post is still displayed. Thank you anyway! – Zkk Sep 27 '16 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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