Problem: I would like to include a post date filter in a parametric search View.
Solution: At this time we do not provide a built-in front-end search control for post date. Our developers have accepted a feature request to add this type of filter, but I do not yet have a release date available for that improvement. In the meantime, you have the ability to provide front-end search controls for dates in custom fields, so you could use the save_post API to copy the publish date into a custom field as a timestamp, then insert the custom date field as a filter in your custom search View controls.
Add this custom code to your child theme's functions.php file:
function copy_custom_date_field ( $post_id ) { // only copy over the publish date on original posts $status = get_post_status( $post_id ); $pubdate = get_post_meta( $post_id, 'wpcf-issue-date', true); if ( $status != 'publish' || $pubdate ) return; $pubdate = get_the_date( 'U', $post_id ); update_post_meta( $post_id, 'wpcf-issue-date', $pubdate, '' ); } add_action( 'save_post', 'copy_custom_date_field', 1000 );
Replace "wpcf-issue-date" in both places with the slug of your custom field, using the wpcf- prefix. So if your custom field slug is "custom-post-date" then you should use "wpcf-custom-post-date".
Relevant Documentation:
https://toolset.com/documentation/user-guides/date-filters/
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 2 replies, has 3 voices.
Last updated by 6 years, 8 months ago.
Assisted by: Christian Cox.