wpseek.com
Uma área de pesquisa sobre o WordPress para devs e autores do tema



wp_random_content_pre_get_posts › WordPress Function

Desde7.2.0
Obsoleton/a
› wp_random_content_pre_get_posts ( $query )
Parâmetros:
  • (WP_Query) $query The WP_Query instance (passed by reference).
    Required: Yes
Definido em:
Codex:

Limits the main query to posts eligible for random content requests.

The main query is used to select the random post so the request runs the same query, and the same filters, as the archive it is randomizing. As such, callbacks on the {@see 'pre_get_posts'} action may modify the posts eligible for selection, for example to limit the post types or exclude a category: add_action( 'pre_get_posts', static function ( WP_Query $query ) { if ( wp_is_random_content_query( $query ) ) { $query->set( 'category__not_in', array( 1 ) ); } } ); Only randomable post types and published posts without a password are eligible. The number and order of posts are enforced by Ver página de detalhe para wp_random_content_post_limits »

" href="https://pt.wpseek.com/function/%5Cwp_random_content_post_limits/">wp_random_content_post_limits
and Ver página de detalhe para wp_random_content_posts_orderby »

" href="https://pt.wpseek.com/function/%5Cwp_random_content_posts_orderby/">wp_random_content_posts_orderby
, so callbacks modifying them on archives do not affect the selection. The random post IDs the post is selected from are stored in the random_sample_ids query variable, see Ver página de detalhe para wp_get_random_content_sample_ids »

" href="https://pt.wpseek.com/function/%5Cwp_get_random_content_sample_ids/">wp_get_random_content_sample_ids
. Added to the Ver página de detalhe para 'pre_get_posts'} action by {@see WP::handle_random »

" href="https://pt.wpseek.com/function/%26%23039%3Bpre_get_posts%26%23039%3B%7D+action+by+%7B%40see+%5CWP%3A%3Ahandle_random/">'pre_get_posts'} action by {@see WP::handle_random
while the random content query runs, so it runs after other callbacks.


Fonte

function wp_random_content_pre_get_posts( $query ): void {
	if ( ! wp_is_random_content_query( $query ) ) {
		return;
	}

	$query->set( 'post_type', wp_get_random_content_post_types( $query ) );
	$query->set( 'post_status', 'publish' );
	$query->set( 'has_password', false );
	$query->set( 'random_sample_ids', wp_get_random_content_sample_ids() );
	$query->set( 'ignore_sticky_posts', true );
	$query->set( 'no_found_rows', true );
	$query->set( 'update_post_meta_cache', false );
	$query->set( 'update_post_term_cache', false );
	// The order and number of posts are enforced by filters, which a suppressed query skips.
	$query->set( 'suppress_filters', false );
}