WordPress.org

Make WordPress Core

Opened 5 months ago

Last modified 3 months ago

#47777 new defect (bug)

"get_lastpostmodified" does not seem to return the intended value when using custom post types

Reported by: mikaumoto Owned by:
Milestone: 5.4 Priority: normal
Severity: normal Version: 4.4
Component: Posts, Post Types Keywords: needs-unit-tests has-patch
Focuses: Cc:
PR Number:

Description

When I use "get_lastpostmodified" for custom post type,the return value was different from what I thought.

ex.post_type wp,tips

https://usort.jp/wp-content/uploads/image1.png

sql
SELECT post_modified FROM wp_posts WHERE post_type='%s' and post_status='publish' order by post_modified DESC limit 1
SELECT post_date FROM wp_posts WHERE post_type='%s' and post_status='publish' order by post_date DESC limit 1

wp-includes\post.php

<?php
        $lastpostdate = get_lastpostdate( $timezone );
        if ( $lastpostdate > $lastpostmodified ) {
                $lastpostmodified = $lastpostdate;
        }

If understand that when "modified" is older "posted" return value is "posted".

But "lastpostdate" seems "any post_types", I think.

I tried this code.

<?php
        $lastpostdate = get_lastpostdate( $timezone, $post_type );
        if ( $lastpostdate > $lastpostmodified ) {
                $lastpostmodified = $lastpostdate;
        }

https://usort.jp/wp-content/uploads/image2.png

As above, I think "get_lastpostmodified" will return the intended value.

I would like you to consider this matter.
Thank you.

Attachments (3)

image1.png (106.0 KB) - added by mikaumoto 5 months ago.
image2.png (105.1 KB) - added by mikaumoto 5 months ago.
patch.diff (1022 bytes) - added by munyagu 4 months ago.
add $post_type

Download all attachments as: .zip

Change History (5)

@mikaumoto
5 months ago

@mikaumoto
5 months ago

@munyagu
4 months ago

add $post_type

#1 @munyagu
4 months ago

  • Component changed from General to Posts, Post Types
  • Keywords has-patch added

#2 @johnbillion
3 months ago

  • Keywords needs-unit-tests added
  • Milestone changed from Awaiting Review to 5.4
  • Version set to 4.4

Thanks for the report @mikaumoto and thanks for the patch @munyagu.

That patch looks good but this could do with some unit tests.

Note: See TracTickets for help on using tickets.