wpseek.com
Uma área de pesquisa sobre o WordPress para devs e autores do tema
wp_is_random_content_query › WordPress Function
Desde7.2.0
Obsoleton/a
› wp_is_random_content_query ( $query )
| Parâmetros: |
|
| Retorna: |
|
| Definido em: |
|
| Codex: |
Determines whether a query is a request for random content.
A random content request is a front end, main query for the blog home or an archive that includes therandom query variable and at least one randomable post type.
For example example.com/random/ or example.com/random/category/news/.
Singular (including embeds), search, feed, trackback, robots.txt, favicon and sitemap
requests are never random content requests, nor are requests using an HTTP method
other than GET or HEAD. Search
requests are excluded as selecting a random post from search results would run an
uncacheable search query that orders every matching post randomly. Search requests
that include the random query variable are redirected to the search results
by Ver página de detalhe para WP::handle_random »" href="https://pt.wpseek.com/function/%5CWP%3A%3Ahandle_random/">WP::handle_random.Fonte
function wp_is_random_content_query( WP_Query $query ): bool {
if (
! $query->is_random()
|| ! $query->is_main_query()
|| is_admin()
|| ! wp_is_random_content_redirect_enabled()
) {
return false;
}
$request_method = isset( $_SERVER['REQUEST_METHOD'] ) && is_string( $_SERVER['REQUEST_METHOD'] ) ? strtoupper( $_SERVER['REQUEST_METHOD'] ) : '';
if ( 'GET' !== $request_method && 'HEAD' !== $request_method ) {
return false;
}
return array() !== wp_get_random_content_post_types( $query );
}