Make WordPress Core

Changeset 48631


Ignore:
Timestamp:
07/27/2020 02:16:46 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Posts, Post Types: Pass the post type to get_lastpostdate() in get_lastpostmodified().

This ensures that the correct values are being compared when retrieving the result for custom post types.

Additionally, pass the $post_type parameter to get_lastpostdate and get_lastpostmodified filters.

Props mikaumoto, munyagu, donmhico, johnbillion, SergeyBiryukov.
Fixes #47777.

Location:
trunk
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r48620 r48631  
    66216621 */
    66226622function get_lastpostdate( $timezone = 'server', $post_type = 'any' ) {
     6623    $date = _get_last_post_time( $timezone, 'date', $post_type );
     6624
    66236625    /**
    66246626     * Filters the most recent time that a post on the site was published.
    66256627     *
    66266628     * @since 2.3.0
    6627      *
    6628      * @param string|false $date     Date the last post was published. False on failure.
    6629      * @param string       $timezone Location to use for getting the post published date.
    6630      *                               See get_lastpostdate() for accepted `$timezone` values.
     6629     * @since 5.5.0 Added the `$post_type` parameter.
     6630     *
     6631     * @param string|false $date      Date the last post was published. False on failure.
     6632     * @param string       $timezone  Location to use for getting the post published date.
     6633     *                                See get_lastpostdate() for accepted `$timezone` values.
     6634     * @param string       $post_type The post type to check.
    66316635     */
    6632     return apply_filters( 'get_lastpostdate', _get_last_post_time( $timezone, 'date', $post_type ), $timezone );
     6636    return apply_filters( 'get_lastpostdate', $date, $timezone, $post_type );
    66336637}
    66346638
     
    66626666     */
    66636667    $lastpostmodified = apply_filters( 'pre_get_lastpostmodified', false, $timezone, $post_type );
     6668
    66646669    if ( false !== $lastpostmodified ) {
    66656670        return $lastpostmodified;
     
    66676672
    66686673    $lastpostmodified = _get_last_post_time( $timezone, 'modified', $post_type );
    6669 
    6670     $lastpostdate = get_lastpostdate( $timezone );
     6674    $lastpostdate     = get_lastpostdate( $timezone, $post_type );
     6675
    66716676    if ( $lastpostdate > $lastpostmodified ) {
    66726677        $lastpostmodified = $lastpostdate;
     
    66776682     *
    66786683     * @since 2.3.0
     6684     * @since 5.5.0 Added the `$post_type` parameter.
    66796685     *
    66806686     * @param string|false $lastpostmodified The most recent time that a post was modified, in 'Y-m-d H:i:s' format.
     
    66826688     * @param string       $timezone         Location to use for getting the post modified date.
    66836689     *                                       See get_lastpostdate() for accepted `$timezone` values.
     6690     * @param string       $post_type        The post type to check.
    66846691     */
    6685     return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone );
     6692    return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone, $post_type );
    66866693}
    66876694
Note: See TracChangeset for help on using the changeset viewer.