wpseek.com
Un motore di ricerca WordPress per sviluppatori e autori di temi



wp_is_random_content_query › WordPress Function

Da7.2.0
Deprecaton/a
› wp_is_random_content_query ( $query )
Parametri:
  • (WP_Query) $query The query to check.
    Richiesto: Sì
Ritorna:
  • (bool) True if the query is a request for random content, false otherwise.
Definito a:
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, an archive, or search results that includes the random query variable and at least one randomable post type. For example example.com/random/, example.com/random/category/news/ or example.com/?s=foo&random. Singular (including embeds) and feed requests are never random content requests, nor are requests using an HTTP method other than GET or HEAD.


Sorgenti

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 );
}