Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API request: language aware get_lastpostmodified and get_lastpostdate #1096

Open
6 tasks done
RavanH opened this issue Aug 18, 2022 · 3 comments
Open
6 tasks done

API request: language aware get_lastpostmodified and get_lastpostdate #1096

RavanH opened this issue Aug 18, 2022 · 3 comments

Comments

@RavanH
Copy link

RavanH commented Aug 18, 2022

Prerequisites

  • This is not a usage question (Those should be directed to the community supported forum, unless this is a question about Polylang Pro in which case you should use the helpdesk).
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest master branch of Polylang and the latest WordPress version.
  • This bug happens with only Polylang plugin active
  • This bug happens with a default WordPress theme active
  • I can reproduce this bug consistently

Steps to reproduce the issue

  1. Create an archive template file and use either get_lastpostmodified or get_lastpostdate to get and display the last post date.
  2. Visit an archive page in one language (for example /fr/category/term)
  3. Compare it with the same archive for another language (for example /en/category/term)

Expected behavior and actual behavior

When I follow those steps, I see both archive pages show the same last post date: the absolute last post date irrespective of the selected language.

I was expecting to see the last post date for the selected language OR hoping to find a dedicated function like pll_get_lastpostdate available in api.php

@Chouby
Copy link
Contributor

Chouby commented Aug 24, 2022

Hi Rolf!

Great to read you again. It indeed looks like something we should add. I'll investigate a bit to check how it could be feasible.

Related: #309

@Chouby
Copy link
Contributor

Chouby commented Aug 24, 2022

Hum... After some investigations on the topic, I would say that we should take great care not to harm performance.

This ticket reports performance issues for the queries run by get_lastpostmodified() and get_lastpostdate(). Our own queries would be even slower as we would need to join the posts table to the term_relationships. and we would need to multiply the number of queries per the number of languages.

Additionnally the filter pre_get_lastpostmodified allows to bypass the WP queries for get_lastpostmodified() but we don't have an equivalent filter for get_lastpostdate(). That means that if we decide to filter these functions both WP queries and ours would run.

This comment is however quite interesting as it proposes an alternative solution for some use cases: Would it work for you to loop over the posts you queried in your archive template instead of firing an additional DB query to get the absolute last modified post? I guess it would be ok for page 1 but not if you want to display the date on page 2 and next.

@Chouby
Copy link
Contributor

Chouby commented Aug 24, 2022

Note for ourselves:
Both functions use _get_last_post_time().
The cache is deleted in _transition_post_status(), itself hooked to the action transition_post_status.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants