WordPress.org

Make WordPress Core

Opened 8 months ago

Last modified 4 weeks ago

#47777 reviewing defect (bug)

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

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

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 (4)

image1.png (106.0 KB) - added by mikaumoto 8 months ago.
image2.png (105.1 KB) - added by mikaumoto 8 months ago.
patch.diff (1022 bytes) - added by munyagu 8 months ago.
add $post_type
47777.2.diff (3.4 KB) - added by donmhico 2 months ago.
Add unit test

Download all attachments as: .zip

Change History (14)

@mikaumoto
8 months ago

@mikaumoto
8 months ago

@munyagu
8 months ago

add $post_type

#1 @munyagu
8 months ago

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

#2 @johnbillion
6 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.

@donmhico
2 months ago

Add unit test

#3 follow-up: @donmhico
2 months ago

  • Keywords has-unit-tests added; needs-unit-tests removed

Thanks @mikaumoto and @munyagu for your efforts on this ticket. @johnbillion I added unit test in 47777.2.diff. Let's try to include this in 5.4 if possible.

#4 in reply to: ↑ 3 @munyagu
2 months ago

Replying to donmhico:

Thanks @mikaumoto and @munyagu for your efforts on this ticket. @johnbillion I added unit test in 47777.2.diff. Let's try to include this in 5.4 if possible.

Thanks!

#5 @audrasjb
6 weeks ago

Hi there,

With Beta 3 approaching, we'll need a decision and a commit action very soon.
For Component maintainers: if you don't feel the current patch is ready to land in WP 5.4 in the next few day, it's could be better to move it to 5.5. We're leaving it in the milestone for now.

This ticket was mentioned in Slack in #core by david.baumwald. View the logs.


5 weeks ago

#7 @SergeyBiryukov
5 weeks ago

  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

This ticket was mentioned in Slack in #core by david.baumwald. View the logs.


4 weeks ago

#9 @davidbaumwald
4 weeks ago

  • Milestone changed from 5.4 to 5.5

With 5.4 RC1 landing tomorrow, this is being moved to 5.5. If any maintainer or committer feels this can be resolved in time or wishes to assume ownership during a specific cycle, feel free to update the milestone.

#10 @SergeyBiryukov
4 weeks ago

47777.2.diff looks good, however, if we're adding the $post_type parameter to the get_lastpostmodified filter, the same should be done for get_lastpostdate.

Note: See TracTickets for help on using tickets.