_find_post_by_old_date( string $post_type ): int 
 This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Use wp_old_slug_redirect() instead.   Find the post ID for redirecting an old date.   Description See also  
wp_old_slug_redirect()     Parameters   $post_type string Required    The current post type based on the query vars.      Return int The Post ID.   Source  File: wp-includes/query.php. View all references  function _find_post_by_old_date( $post_type ) {
	global $wpdb;

	$date_query = '';
	if ( get_query_var( 'year' ) ) {
		$date_query .= $wpdb->prepare( ' AND YEAR(pm_date.meta_value) = %d', get_query_var( 'year' ) );
	}
	if ( get_query_var( 'monthnum' ) ) {
		$date_query .= $wpdb->prepare( ' AND MONTH(pm_date.meta_value) = %d', get_query_var( 'monthnum' ) );
	}
	if ( get_query_var( 'day' ) ) {
		$date_query .= $wpdb->prepare( ' AND DAYOFMONTH(pm_date.meta_value) = %d', get_query_var( 'day' ) );
	}

	$id = 0;
	if ( $date_query ) {
		$query        = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta AS pm_date, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_date' AND post_name = %s" . $date_query, $post_type, get_query_var( 'name' ) );
		$key          = md5( $query );
		$last_changed = wp_cache_get_last_changed( 'posts' );
		$cache_key    = "find_post_by_old_date:$key:$last_changed";
		$cache        = wp_cache_get( $cache_key, 'posts' );
		if ( false !== $cache ) {
			$id = $cache;
		} else {
			$id = (int) $wpdb->get_var( $query );
			if ( ! $id ) {
				// Check to see if an old slug matches the old date.
				$id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts, $wpdb->postmeta AS pm_slug, $wpdb->postmeta AS pm_date WHERE ID = pm_slug.post_id AND ID = pm_date.post_id AND post_type = %s AND pm_slug.meta_key = '_wp_old_slug' AND pm_slug.meta_value = %s AND pm_date.meta_key = '_wp_old_date'" . $date_query, $post_type, get_query_var( 'name' ) ) );
			}
			wp_cache_set( $cache_key, $id, 'posts' );
		}
	}

	return $id;
}
   Related  Uses    Uses Description      wp_cache_get_last_changed() wp-includes/functions.php   Gets last changed date for the specified cache group.     wp_cache_set() wp-includes/cache.php   Saves the data to the cache.     get_query_var() wp-includes/query.php   Retrieves the value of a query variable in the WP_Query class.     wp_cache_get() wp-includes/cache.php   Retrieves the cache contents from the cache by key and group.     wp8b7c:f320:99b9:690f:4595:cd17:293a:c069get_var() wp-includes/class-wpdb.php   Retrieves one variable from the database.     wp8b7c:f320:99b9:690f:4595:cd17:293a:c069prepare() wp-includes/class-wpdb.php   Prepares a SQL query for safe execution.   
   Used By    Used By Description      wp_old_slug_redirect() wp-includes/query.php   Redirect old slugs to the correct permalink.   
    Changelog    Version Description     4.9.3 Introduced.    

    
{'path': 'public/docs/wordpress/functions/_find_post_by_old_date.html', 'source': 'DevDocs.IO'}