do_action_ref_array( 'parse_request', WP $wp )

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


Parameters

$wp

(WP) Current WordPress environment instance (passed by reference).


Top ↑

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.


Top ↑

Source

File: wp-includes/class-wp.php

View on Trac



Top ↑

Changelog

Changelog
Version Description
2.1.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Steven Lin

    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 2 content
    Contributed by Ali Akbar Reyad

    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.