this custom post type is created by a plugin, I can't update the
register_post_type
code
You can use either the register_post_type_args
or register_<post type>_post_type_args
hook to filter the post type args like the publicly_queryable
in your case. See an example below which uses the former hook, where I also set exclude_from_search
to true
to exclude posts with the magicai-documents
post type from front end search results.
<?php
add_filter( 'register_post_type_args', 'my_filter_post_type_args', 10, 2 );
function my_filter_post_type_args( $args, $post_type ) {
if ( 'magicai-documents' === $post_type ) {
$args['publicly_queryable'] = false;
$args['exclude_from_search'] = true;
}
return $args;
}
If the post type should only be made public on the admin side, then you can set the public
arg to false
, and then set show_ui
and show_in_nav_menus
to true
.
Alternatively, you could hook on an action like template_redirect
and do a conditional tag check like if ( is_singular( 'magicai-documents' ) || is_post_type_archive( 'magicai-documents' ) ) { display a 404 error or (do) something else }
, and/or you could filter the WP_Query
args using the pre_get_posts
action, but changing the appropriate post type args is much easier.