get_feed_build_date

The timeline below displays how wordpress function get_feed_build_date has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Gets the UTC time of the most recently modified post from WP_Query.
 *
 * If viewing a comment feed, the time of the most recently modified
 * comment will be returned.
 *
 * @global WP_Query $wp_query WordPress Query object.
 *
 * @since 5.2.0
 *
 * @param string $format Date format string to return the time in.
 * @return string|false The time in requested format, or false on failure.
 */
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);
}

WordPress Version: .10

/**
 * Get the UTC time of the most recently modified post from WP_Query.
 *
 * If viewing a comment feed, the time of the most recently modified
 * comment will be returned.
 *
 * @global WP_Query $wp_query WordPress Query object.
 *
 * @since 5.2.0
 *
 * @param string $format Date format string to return the time in.
 * @return string|false The time in requested format, or false on failure.
 */
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);
}

WordPress Version: 3.1

/**
 * Get the timestamp of the most recently modified post from WP_Query.
 *
 * If viewing a comment feed, the timestamp of the most recently modified
 * comment will be returned.
 *
 * @global WP_Query $wp_query WordPress Query object.
 *
 * @since 5.2.0
 *
 * @param string $format Format of the timestamp to return, passed to mysql2date.
 *
 * @return string The timestamp.
 */
function get_feed_build_date($format)
{
    global $wp_query;
    if (empty($wp_query) || !$wp_query->have_posts()) {
        // Fallback to last time any post was modified or published.
        return get_lastpostmodified('GMT');
    }
    // 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), new DateTimeZone('UTC'));
    $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 $max_modified_time Date the last post or comment was modified in the query.
     * @param string $format            The date format requested in get_feed_build_date.
     */
    return apply_filters('get_feed_build_date', $max_modified_time, $format);
}

WordPress Version: 5.3

/**
 * Get the timestamp of the most recently modified post from WP_Query.
 *
 * If viewing a comment feed, the timestamp of the most recently modified
 * comment will be returned.
 *
 * @global WP_Query $wp_query WordPress Query object.
 *
 * @since 5.2.0
 *
 * @param string $format Format of the timestamp to return, passed to mysql2date.
 *
 * @return string The timestamp.
 */
function get_feed_build_date($format)
{
    global $wp_query;
    if (empty($wp_query) || !$wp_query->have_posts()) {
        // Fallback to last time any post was modified or published.
        return get_lastpostmodified('GMT');
    }
    // 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.
    $max_modified_time = mysql2date($format, max($modified_times), false);
    /**
     * Filters the date the last post or comment in the query was modified.
     *
     * @since 5.2.0
     *
     * @param string $max_modified_time Date the last post or comment was modified in the query.
     * @param string $format            The date format requested in get_feed_build_date.
     */
    return apply_filters('get_feed_build_date', $max_modified_time, $format);
}

WordPress Version: 2.1

/*
 * Get the timestamp of the most recently modified post from WP_Query.
 *
 * If viewing a comment feed, the timestamp of the most recently modified
 * comment will be returned.
 *
 * @global WP_Query  $wp_query The global WP_Query object.
 *
 * @since 5.2.0
 *
 * @param string $format Format of the timestamp to return, passed to mysql2date.
 *
 * @return string The timestamp.
 */
function get_feed_build_date($format)
{
    global $wp_query;
    if (empty($wp_query) || !$wp_query->have_posts()) {
        // Fallback to last time any post was modified or published.
        return get_lastpostmodified('GMT');
    }
    // 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.
    $max_modified_time = mysql2date($format, max($modified_times), false);
    /**
     * Filters the date the last post or comment in the query was modified.
     *
     * @since 5.2.0
     *
     * @param string $max_modified_time Date the last post or comment was modified in the query.
     * @param string $format            The date format requested in get_feed_build_date.
     */
    return apply_filters('get_feed_build_date', $max_modified_time, $format);
}

WordPress Version: 5.2

/*
 * Get the timestamp of the most recently modified post from WP_Query.
 *
 * If viewing a comment feed, the timestamp of the most recently modified
 * comment will be returned.
 *
 * @global WP_Query  $wp_query The global WP_Query object.
 *
 * @since 5.2.0
 *
 * @param string $format Format of the timestamp to return, passed to mysql2date.
 *
 * @return string The timestamp.
 */
function get_feed_build_date($format)
{
    global $wp_query;
    if (empty($wp_query) || !$wp_query->have_posts()) {
        // Fallback to last time any post was modified or published.
        return get_lastpostmodified('GMT');
    }
    // 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.
    $max_modified_time = max(array_map(function ($time) use ($format) {
        return mysql2date($format, $time, false);
    }, $modified_times));
    /**
     * Filters the date the last post or comment in the query was modified.
     *
     * @since 5.2.0
     *
     * @param string $max_modified_time Date the last post or comment was modified in the query.
     * @param string $format            The date format requested in get_feed_build_date.
     */
    return apply_filters('get_feed_build_date', $max_modified_time, $format);
}