get_feed_build_date

函数
get_feed_build_date ( $format )
参数
  • (string) $format Date format string to return the time in.
    Required:
返回值
  • (string|false) The time in requested format, or false on failure.
定义位置
相关方法
get_file_dataget_theme_updatesget_embed_templateget_the_modified_dateget_the_date
引入
5.2.0
弃用
-

get_feed_build_date: 这个函数用来检索一个RSS提要的建立日期。构建日期是用来指示馈送最后更新的时间。

从WP_Query获取最近修改的文章的UTC时间。

如果查看评论源,将返回最近修改的评论的时间。

function get_feed_build_date( $format ) {
	global $wp_query;

	$datetime          = false;
	$max_modified_time = false;
	$utc               = new DateTimeZone( 'UTC' );

	if ( ! empty( $wp_query ) && $wp_query->have_posts() ) {
		// Extract the post modified times from the posts.
		$modified_times = wp_list_pluck( $wp_query->posts, 'post_modified_gmt' );

		// If this is a comment feed, check those objects too.
		if ( $wp_query->is_comment_feed() && $wp_query->comment_count ) {
			// Extract the comment modified times from the comments.
			$comment_times = wp_list_pluck( $wp_query->comments, 'comment_date_gmt' );

			// Add the comment times to the post times for comparison.
			$modified_times = array_merge( $modified_times, $comment_times );
		}

		// Determine the maximum modified time.
		$datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', max( $modified_times ), $utc );
	}

	if ( false === $datetime ) {
		// Fall back to last time any post was modified or published.
		$datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', get_lastpostmodified( 'GMT' ), $utc );
	}

	if ( false !== $datetime ) {
		$max_modified_time = $datetime->format( $format );
	}

	/**
	 * Filters the date the last post or comment in the query was modified.
	 *
	 * @since 5.2.0
	 *
	 * @param string|false $max_modified_time Date the last post or comment was modified in the query, in UTC.
	 *                                        False on failure.
	 * @param string       $format            The date format requested in get_feed_build_date().
	 */
	return apply_filters( 'get_feed_build_date', $max_modified_time, $format );
}

常见问题

FAQs
查看更多 >