wpseek.com
Uma área de pesquisa sobre o WordPress para devs e autores do tema
wp_random_content_redirect › WordPress Function
Desde7.2.0
Obsoleton/a
› wp_random_content_redirect ( Sem parâmetros )
| Definido em: |
|
| Codex: |
Redirects random content requests to the randomly selected post.
Added to the {@see 'template_redirect'} action at priority 100 by Ver página de detalhe para WP::handle_random »" href="https://pt.wpseek.com/function/%5CWP%3A%3Ahandle_random/">WP::handle_random once the main query has selected the random post, so the redirect is sent after the request is set up and the {@see 'wp'} action has fired. The headers preventing the redirect being cached or indexed are sent with it. The post is read from the main query rather than the current query, so the redirect is still sent when an earlier callback replaces the current query, for example by calling Ver página de detalhe para query_posts »" href="https://pt.wpseek.com/function/%5Cquery_posts/">query_posts. The request ends once a post is selected. The redirect is to the post's permalink as returned by Ver página de detalhe para get_permalink »" href="https://pt.wpseek.com/function/%5Cget_permalink/">get_permalink, including a permalink filtered to be on another site. If no post is selected, for example on an empty archive, Ver página de detalhe para WP::handle_random »" href="https://pt.wpseek.com/function/%5CWP%3A%3Ahandle_random/">WP::handle_random handles the request as a 404.Fonte
function wp_random_content_redirect(): void {
global $wp_the_query;
if (
! $wp_the_query instanceof WP_Query
|| ! wp_is_random_content_query( $wp_the_query )
|| ! $wp_the_query->post instanceof WP_Post
) {
return;
}
nocache_headers();
if ( ! headers_sent() ) {
header( 'X-Robots-Tag: noindex, follow' );
}
$location = get_permalink( $wp_the_query->post );
wp_redirect( $location, 302 );
exit;
}