WordPress.org

Make WordPress Core

Opened 12 months ago

Closed 8 days ago

Last modified 7 days ago

#47777 closed defect (bug) (fixed)

"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 (6)

image1.png (106.0 KB) - added by mikaumoto 12 months ago.
image2.png (105.1 KB) - added by mikaumoto 12 months ago.
patch.diff (1022 bytes) - added by munyagu 12 months ago.
add $post_type
47777.2.diff (3.4 KB) - added by donmhico 6 months ago.
Add unit test
47777.3.diff (6.2 KB) - added by munyagu 4 weeks ago.
47777.4.diff (7.8 KB) - added by munyagu 4 weeks ago.
Change to add multiple posts to each post_type

Download all attachments as: .zip

Change History (19)

@mikaumoto
12 months ago

@mikaumoto
12 months ago

@munyagu
12 months ago

add $post_type

#1 @munyagu
12 months ago

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

#2 @johnbillion
11 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
6 months ago

Add unit test

#3 follow-up: @donmhico
6 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
6 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
5 months 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 months ago

#7 @SergeyBiryukov
5 months 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.


5 months ago

#9 @davidbaumwald
5 months 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
5 months 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.

@munyagu
4 weeks ago

#11 @munyagu
4 weeks ago

Add post_type parameter and a test to get_lastpostdate as well.
This is my first test code, and I relied heavily on @donmhico's patch.

@munyagu
4 weeks ago

Change to add multiple posts to each post_type

#12 @SergeyBiryukov
8 days ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 48631:

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.

#13 @SergeyBiryukov
7 days ago

In 48633:

Tests: Add more fixtures to get_lastpostdate() and get_lastpostmodified() tests.

Follow-up to [48631].

Props munyagu.
See #47777.

Note: See TracTickets for help on using tickets.