Hiding posts – WP Hide Post not working

here is a code example to hide post. However you need to use a custom meta for this to work. So, add a new meta with the post you want to hide. Use meta key name as ‘hidethis’ and use value ‘1’. Don’t use the quote marks, just the texts.

Next this is to add a code to your themes functions.php. You can edit it directly from your wp-admin -> themes -> editor page. Just find the file name (on right side) functions.php and add the following code, then hit update button.

add_action( 'pre_get_posts', 'pre_get_posts_127256', 9999 );
function pre_get_posts_127256($q){
    if( is_admin() )
        return;

    if( is_singular() )
        return;

    $mq = $q->get('meta_query');
    $nm = array('key' => 'hidethis', 'compare' => 'NOT EXISTS');
    $mq[] = $nm;

    $q->set('meta_query', $mq);
}

This should be hiding the post u added meta key ‘hidethis’ with a value.