# Exclude draft or private status post

If you would like to exclude page who is in draft or private you can add the code below:

```php
<?php

add_action('pre_get_posts', 'custom_weglot_translated_search_redirect');
function custom_weglot_translated_search_redirect() {
    global $post;
    if ($post) {
        $post_status = get_post_status($post->ID);
        if (!function_exists('weglot_get_original_language') || !function_exists('weglot_get_current_language')) {
            return;
        }
        if (($post_status == 'draft' || $post_status == 'private') && !is_admin() && weglot_get_original_language() != weglot_get_current_language()) {
            wp_redirect(weglot_get_full_url_no_language(), 301);
            exit;
        }
    }
}

add_filter('weglot_button_html', 'custom_weglot_translated_search_no_selector');
function custom_weglot_translated_search_no_selector($button_html) {
    global $post;
    if ($post) {
        $post_status = get_post_status($post->ID);
        if (($post_status == 'draft' || $post_status == 'private') && !is_admin()) {
            return '';
        }
    }
    return $button_html;
}

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.weglot.com/wordpress/use-cases/exclude-the-search-page-from-translations-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
