do_action_ref_array( ‘parse_request’, WP $wp )

Fires once all query variables for the current request have been parsed.

Parameters

$wpWP
Current WordPress environment instance (passed by reference).

More Information

This action hook is executed at the end of WordPress’s built-in request parsing method in the main WP() class.

Attention! The parse_request hook affects only the main query and not queries made with wp_query, for example.

Source

do_action_ref_array( 'parse_request', array( &$this ) );

Changelog

VersionDescription
2.1.0Introduced.

User Contributed Notes

  1. Skip to note 3 content

    Example migrated from Codex:

    add_action( 'parse_request', 'change_post_per_page_wpent' );
    
    function change_post_per_page_wpent( $query ) {
        if (  'my_cpt' == $query->query_vars['post_type'] ) {
            $query->query_vars[ 'posts_per_page' ] = 3;
        }
        
        return $query;
    }
  2. Skip to note 4 content

    Example: Search by post ID also in dashboard

    add_action( 'parse_request', function( $wp ) {
    	global $pagenow;
    
    	if ( ! is_admin() && 'edit.php' !== $pagenow ) {
    		return;
    	}
    
    	// Check query parameter [s] exist
    	if ( ! isset( $wp->query_vars['s'] ) ) {
    		return;
    	}
    
    	// Check numeric value
    	$post_id = absint( $wp->query_vars['s'] );
    	if ( ! $post_id ) {
    		return;
    	}
    
    	unset( $wp->query_vars['s'] );
    
    	$wp->query_vars['p'] = $post_id;
    } );

You must log in before being able to contribute a note or feedback.