Title: WP_Rewrite::get_date_permastruct
Published: April 25, 2014
Last modified: April 28, 2025

---

# WP_Rewrite::get_date_permastruct(): string|false

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_rewrite/get_date_permastruct/?output_format=md#description)
 * [Return](https://developer.wordpress.org/reference/classes/wp_rewrite/get_date_permastruct/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rewrite/get_date_permastruct/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rewrite/get_date_permastruct/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rewrite/get_date_permastruct/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_rewrite/get_date_permastruct/?output_format=md#wp--skip-link--target)

Retrieves date permalink structure, with year, month, and day.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_rewrite/get_date_permastruct/?output_format=md#description)󠁿

The permalink structure for the date, if not set already depends on the permalink
structure. It can be one of three formats. The first is year, month, day; the second
is day, month, year; and the last format is month, day, year. These are matched 
against the permalink structure for which one is used. If none matches, then the
default will be used, which is year, month, day.

Prevents post ID and date permalinks from overlapping. In the case of post_id, the
date permalink will be prepended with front permalink with ‘date/’ before the actual
permalink to form the complete date permalink structure.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_rewrite/get_date_permastruct/?output_format=md#return)󠁿

 string|false Date permalink structure on success, false on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rewrite/get_date_permastruct/?output_format=md#source)󠁿

    ```php
    public function get_date_permastruct() {
    	if ( isset( $this->date_structure ) ) {
    		return $this->date_structure;
    	}

    	if ( empty( $this->permalink_structure ) ) {
    		$this->date_structure = '';
    		return false;
    	}

    	// The date permalink must have year, month, and day separated by slashes.
    	$endians = array( '%year%/%monthnum%/%day%', '%day%/%monthnum%/%year%', '%monthnum%/%day%/%year%' );

    	$this->date_structure = '';
    	$date_endian          = '';

    	foreach ( $endians as $endian ) {
    		if ( str_contains( $this->permalink_structure, $endian ) ) {
    			$date_endian = $endian;
    			break;
    		}
    	}

    	if ( empty( $date_endian ) ) {
    		$date_endian = '%year%/%monthnum%/%day%';
    	}

    	/*
    	 * Do not allow the date tags and %post_id% to overlap in the permalink
    	 * structure. If they do, move the date tags to $front/date/.
    	 */
    	$front = $this->front;
    	preg_match_all( '/%.+?%/', $this->permalink_structure, $tokens );
    	$tok_index = 1;
    	foreach ( (array) $tokens[0] as $token ) {
    		if ( '%post_id%' === $token && ( $tok_index <= 3 ) ) {
    			$front = $front . 'date/';
    			break;
    		}
    		++$tok_index;
    	}

    	$this->date_structure = $front . $date_endian;

    	return $this->date_structure;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-rewrite.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-rewrite.php#L495)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-rewrite.php#L495-L540)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rewrite/get_date_permastruct/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_Rewrite::rewrite_rules()](https://developer.wordpress.org/reference/classes/wp_rewrite/rewrite_rules/)`wp-includes/class-wp-rewrite.php` |

Constructs rewrite matches and queries from permalink structure.

  | 
| [WP_Rewrite::get_year_permastruct()](https://developer.wordpress.org/reference/classes/wp_rewrite/get_year_permastruct/)`wp-includes/class-wp-rewrite.php` |

Retrieves the year permalink structure without month and day.

  | 
| [WP_Rewrite::get_month_permastruct()](https://developer.wordpress.org/reference/classes/wp_rewrite/get_month_permastruct/)`wp-includes/class-wp-rewrite.php` |

Retrieves the month permalink structure without day and with year.

  | 
| [WP_Rewrite::get_day_permastruct()](https://developer.wordpress.org/reference/classes/wp_rewrite/get_day_permastruct/)`wp-includes/class-wp-rewrite.php` |

Retrieves the day permalink structure with month and year.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rewrite/get_date_permastruct/?output_format=md#changelog)󠁿

| Version | Description | 
| [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rewrite%2Fget_date_permastruct%2F)
before being able to contribute a note or feedback.