Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#34325 closed defect (bug) (invalid)

get_posts seems to have issues including posts "published in the past"

Reported by: kevingimbel's profile kevingimbel Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.3
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

We just notices a potential bug with the get_posts function.

At out site we use it in a simple recent-post shotcode to get recent posts. The exact "query" is below.

get_posts(
    array(
      'orderby' => 'date',
      'order' => 'DESC',
      'post_type' => 'post',
      'showposts' => 3,
      'post_status' => 'publish'
    )
  );

However, when we published an article today and marked it as "Published in September" the post didn't show up. Strangely, it showed up when logged in to the backend.

Workaround: A quick workaround was to create a new post and immediately delete it, then the "old" posts would show up.

The general post list did show the posts correctly all the time.

Change History (4)

#1 @swissspidy
9 years ago

  • Keywords reporter-feedback added

Hey there

Thanks for your report. Can you explain a bit more which date you set the post too?

Also, have you tried to debug the resulting query? What was the final database query like?

Perhaps it is a caching issue, a plugin conflict or there were simply some sticky posts. WP_Query has many unit tests, so this bug seems kinda unlikely to me.

#2 @boonebgorges
9 years ago

  • Keywords close added

Hi kevingimbel - Welcome to Trac!

As swissspidy noted, the fact that you were able to work around the issue by creating and deleting a new post makes it sound like a caching issue. And the fact that you're not seeing stale content on wp-admin makes it sound like it might be related to a static page caching tool, which only operates on the front-end. Are you using anything like WP Super Cache or some other page cache? It's possible that your caching plugin has a bug that causes the page cache not to be regenerated when you change the publish date on a post.

(As a side note, WP_Query itself does not cache these kinds of queries at all. So it's highly likely that this is *not* a core bug.)

#3 @kevingimbel
9 years ago

Hey @boonebgorges and @swissspidy - sorry for the delayed reply!

In fact it it can be the caching. We're having this site on WPEngine.com and they use a mixture of caching tools if I'm not mistaken.

I think this issue can be closed then, since it is most likely related to the cache.

#4 @swissspidy
9 years ago

  • Keywords reporter-feedback close removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

No worries, thanks for your reply! Closing this then :)

Note: See TracTickets for help on using tickets.