Function and usage of get_feed_build_date() in wordpress


Answers ( 1 )


    The get_feed_build_date() function in WordPress is designed to retrieve the UTC time of the most recently modified post or comment, depending on the context of the feed you are viewing. This function is particularly useful for feed templates, where it can help in generating accurate last modified headers.

    Function Overview:

    • Function Name: get_feed_build_date()
    • Return Type: string|false


    • Primary Purpose: This function fetches the UTC time of the most recently modified post or comment from the WordPress Query (WP_Query). The distinction between posts and comments is based on the type of feed being viewed.
    • Context-Sensitive: If you are viewing a post feed, it returns the modification time of the most recently updated post. Conversely, if viewing a comment feed, it returns the time of the most recently modified comment.


    • $format (string, required): This parameter specifies the format in which the date and time should be returned. The format string should be compatible with PHP's date formatting conventions. For example, 'Y-m-d H:i:s' would return the date and time in a format like '2024-01-07 12:45:00'.

    Return Values:

    • Success: If the function successfully retrieves the time, it returns a string representing the date and time in the specified format.
    • Failure: If the function fails to retrieve the time (for instance, if there are no posts or comments), it returns false.

    Sample Usage:

    // Get the last modified time of the most recent post or comment in 'Y-m-d H:i:s' format
    $last_modified = get_feed_build_date('Y-m-d H:i:s');
    if ( false !== $last_modified ) {
        echo 'Last Modified Time: ' . $last_modified;
    } else {
        echo 'Unable to retrieve the last modified time.';

    In this example, get_feed_build_date() is called with a specific date format. It checks whether the function returns a valid string. If it does, it prints the last modified time; otherwise, it handles the failure case by indicating that the time could not be retrieved.

    This function is useful for maintaining up-to-date feeds, ensuring that feed readers and aggregators can accurately reflect the most recent changes in your WordPress site's content.

Leave an answer