Add methods to hide filled and expired posts#2449
Closed
anaemnesis wants to merge 20 commits intotrunkfrom
Closed
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1884
Changes proposed in this Pull Request
get_filled_job_listings(), (2),get_expired_job_listingsand (3)maybe_hide_filled_expired_job_listings_from_searchpost__not_inparameter is applied to$query->setwhen not in WP Admin, and when on a WP search results page.Unlike the previous implementation, this one relies on
get_posts()andmeta_querybut without the expensiveORrelation.Because
expiredjobs already have their post status updated toexpiredif a post's expiry date is set in the past or elapses, we don't need tometa_queryfor expired posts but can instead look forjob_listingswith anexpiredpost status.We don't have the same luxury with
filledposts, but we can do a singularmeta_querywithout any relations to retrieve these.My understanding is that these changes should be far less expensive than the previous implementation.
To further help with performance, the results of
get_filled_job_listingsandget_expired_job_listingsare stored in a transient that is expired every 24 hours, which lines up with the various job expiration methods.Either transient is then cleared on post update if: (1) we're looking at a job listing, (2) the '_filled' post meta has been updated, or (3) the post status has changed from
publishtoexpired,trashor vice-versa.Testing instructions
Expiredwith an expiry date in the past, orFilledby checking theFilledcheckbox.hide_filled_jobs_transientandhide_expired_jobs_transientis not set. With WP CLI these can be checked withwp transient get hide_filled_jobs_transientandwp transient get hide_expired_jobs_transientexpiredorfilledIf you would like to test on a large dataset, WP CLI can be used to bulk create posts:
Bulk create
ExpiredpostsBulk generate
FilledpostsFilledposts are a little more troublesome because we're working with meta values, andwp post generate, as well aswp post create, do not touch these values.So, you could do something like:
The above can be added to a file on your environment, like
create-filled-posts.sh. Make sure tochmod +x $fileand then./$file.shto execute theforloop and create your posts.Note that when creating posts programmatically you may need to manually clear the transients.