Register post status, exclude from searches


I am trying to register a new post type to hide post in searches but still allow for the post to be seen by url.

function reg_ghost_status(){
    register_post_status( 'ghosted', array(
        'label'                     => 'Ghost Post',
        'publicly_queryable'        => false,
        'exclude_from_search'       => true,
        'public'                    => true, //on false hides everywhere
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
    ) );
add_action( 'init', 'reg_ghost_status' );

I could not get this work and tried all sorts of combinations. It seems since it is ‘public’ it shows everywhere no matter what settings. So I than tried using the pre_set_query but I don’t know how to use exclude instead of include by post_status.

function sxcsexclude_ghost_from_search($query) {
        if ( $query->is_single ) {
             $query->set('perm', 'readable');
             $query->set('post_status', array( 'publish', 'draft', 'ghosted', 'future' ));
            return $query;
add_action( 'pre_get_posts', '11111exclude_ghost_from_search' );

Can someone tell me why the register_post_status is not working.


Tianbo84 4 months 0 Answers 14 views 0

Leave an answer