Adapt with $query->set( 'category__not_in', ARCHIVE_ID );
Either define ARCHIVE_ID or replace with the actual value.
FWIW, these forums themselves extensively use an archive “status” which is in fact a taxonomy term.
]]>
function target_main_category_query_with_conditional_tags( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
if ( is_category() ) {
$query->set( 'category__not_in', 1147 );
}
}
}
]]>
add_action( 'pre_get_posts', 'target_main_category_query_with_conditional_tags' );
function target_main_category_query_with_conditional_tags( $query ) {
if ( ! $query->is_main_query() ) {
$query->set( 'category__not_in', 1147 );
}
}
Still just need to know about stopping posts from showing with a direct URL to the post and stop indexing them in Search Engines.
]]><meta name="robots" content="noindex">
The tag could be injected through the “wp_head” action, but IMO the tag is better off as one of the first tags encountered. The only way to do that is to add the conditional PHP directly to the header.php template. A third option is to have the server send a X-Robots-Tag: noindex
header response.
Oddly, though the meta tag output is necessarily outside of the “Loop”, the loop’s global $post object seems to already have the requested post object assigned, which can be passed directly to other post related functions. A more logical way to get the needed post ID is from get_queried_object_id()
. Use get_the_terms()
to check for the 1147 category because it will use a cached value if it can. wp_get_post_terms() will always hit the DB. It’s important for this code to be efficient because it runs for every front end request.
To send a header instead, use the ‘wp_headers’ filter, conditionally adding the noindex header to the passed array of header data.
Be aware that obeying the noindex tag is optional. Not all search bots will honor it. The major search engine bots like Google say they honor it. Also, Google for one will still crawl the page and follow any links it finds. It honors the noindex tag only by not listing the associated page in search results.
]]>