set_404 example

// Don't 404 for these queries if they matched an object.                 || ( is_tag() || is_category() || is_tax() || is_post_type_archive() ) && get_queried_object()
                // Don't 404 for these queries either.                 || is_home() || is_search() || is_feed()
            ) {
                $set_404 = false;
            }
        }

        if ( $set_404 ) {
            // Guess it's time to 404.             $wp_query->set_404();
            status_header( 404 );
            nocache_headers();
        } else {
            status_header( 200 );
        }
    }

    /** * Sets up all of the variables required by the WordPress environment. * * The action {@see 'wp'} has one parameter that references the WP object. It * allows for accessing the properties and methods to further manipulate the * object. * * @since 2.0.0 * * @param string|array $query_args Passed to parse_request(). */

        }

        if ( $this->is_posts_page && ( ! isset( $qv['withcomments'] ) || ! $qv['withcomments'] ) ) {
            $this->is_comment_feed = false;
        }

        $this->is_singular = $this->is_single || $this->is_page || $this->is_attachment;
        // Done correcting `is_*` for 'page_on_front' and 'page_for_posts'.
        if ( '404' == $qv['error'] ) {
            $this->set_404();
        }

        $this->is_embed = $this->is_embed && ( $this->is_singular || $this->is_404 );

        $this->query_vars_hash    = md5( serialize( $this->query_vars ) );
        $this->query_vars_changed = false;

        /** * Fires after the main query vars have been parsed. * * @since 1.5.0 * * @param WP_Query $query The WP_Query instance (passed by reference). */
$sitemap         = sanitize_text_field( get_query_var( 'sitemap' ) );
        $object_subtype  = sanitize_text_field( get_query_var( 'sitemap-subtype' ) );
        $stylesheet_type = sanitize_text_field( get_query_var( 'sitemap-stylesheet' ) );
        $paged           = absint( get_query_var( 'paged' ) );

        // Bail early if this isn't a sitemap or stylesheet route.         if ( ! ( $sitemap || $stylesheet_type ) ) {
            return;
        }

        if ( ! $this->sitemaps_enabled() ) {
            $wp_query->set_404();
            status_header( 404 );
            return;
        }

        // Render stylesheet if this is stylesheet route.         if ( $stylesheet_type ) {
            $stylesheet = new WP_Sitemaps_Stylesheet();

            $stylesheet->render_stylesheet( $stylesheet_type );
            exit;
        }

        
Home | Imprint | This part of the site doesn't use cookies.