get_query_var( string $var, mixed $default = '' )

Retrieve variable in the WP_Query class.


Description Description


Parameters Parameters

$var

(string) (Required) The variable key to retrieve.

$default

(mixed) (Optional) Value to return if the query variable is not set.

Default value: ''


Top ↑

Return Return

(mixed) Contents of the query variable.


Top ↑

Source Source

File: wp-includes/query.php

function get_query_var( $var, $default = '' ) {
	global $wp_query;
	return $wp_query->get( $var, $default );
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.9.0 The $default argument was introduced.
1.5.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex

    Getting Current Pagination Number

    <?php $paged = get_query_var( 'paged', 1 ); ?>
    
    <h1><?php printf( esc_html__( 'Currently browsing page %s', 'textdomain' ), $paged ); ?></h1>
    

    For getting the current pagination number on a static front page (Page template) you have to use the page query variable:

    <?php  $page = get_query_var( 'page', 1 );  ?>
    <h1><?php printf( esc_html__( 'Currently browsing page %s on a static front page', 'textdomain' ), $page ); ?></h1>
    

    Note: The query variable page holds the pagenumber for a single paginated Post or Page that includes the <!--nextpage--> Quicktag in the post content.

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