WordPress at a glance

is_date() WP 1.5.0

Determines whether the date archive page is displayed. Conditional tag.

This function is part of is_archive() check and contains in itself: is_day(), is_month(), is_year() and etc. (see example 2)

Works based on: WP_Query::is_date()
✈ 1 time = 0.00006s = very fast | 50000 times = 0.02s = speed of light

No Hooks.

Return

true/false.

Usage

is_date();

Examples

#1 Basic usage

if( is_date() )
	echo "It's an archive by date";
else
	echo "It's not an archive by date";

#2 What checks are included in is_date()

is_date() contains in itself functions is_day(), is_month(), is_year() and etc.

This example demonstrates how not to do:

if( is_date() )
	echo "It's an archive by date";
elseif( is_day() )
	echo "It's an archive by day";
else
	echo "This is something else";

In this example, the is_day() condition will never be met. It needs to be checked before is_date().

Notes

  • Global. WP_Query. $wp_query Global WP_Query instance.

Changelog

Since 1.5.0 Introduced.

Code of is date: wp-includes/query.php WP 5.2.2

<?php
function is_date() {
	global $wp_query;

	if ( ! isset( $wp_query ) ) {
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
		return false;
	}

	return $wp_query->is_date();
}

Related Functions

From tag: Conditional tags (page type and request)

More from tag: Conditional tags (all)

More from category: Queries

More from Template Tags: Main Functions

No comments
    Hello, !     Log In . Register