Skip Navigation

[Resolved] Let the user filter results by modified date

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to create a custom search View where Users can filter posts by post modified date using datepicker(s).

Solution: At this time it is not possible to allow Users to filter a View by post date or modified date. It is possible to filter by a custom field date, so the best approach for now is to use custom code to copy the modified date into a custom field on the post.

function copy_modified_date_field( $post_id, $post ){
    if ( 'project' == $post->post_type ) {
        $now = time();
        update_post_meta( $post_id, 'wpcf-modified-date', $now );
    }
}
add_action( 'save_post', 'copy_modified_date_field', 20, 2 );

Relevant Documentation:
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post

This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Our next available supporter will start replying to tickets in about 4.09 hours from now. Thank you for your understanding.

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)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by ahmedI 6 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#759863
missing-date.png
code.png

Hello,

I want to let the users filter results by modified date, i've read the docs and it mentioned that i can find a full date in Date condition but i can't find that option.

As i understand i set a date condition that accept a url param then link that with a control to change that param, please correct me if am wrong.

Attached some shoots.

Thanks in advance.

#763770

Hi, there's not a built-in way to allow Users to filter by post date or by post modified date. In the screenshot you shared, you can see how to add predefined filters to a View. You could define an exact date here, or an exact date range, or some other predefined date comparison.

We do offer the ability for a User to filter by a custom field date, so you could use some custom code that copies the modified date into a custom field whenever a post is saved. Then add a front-end filter based on that custom field. Here's some sample code you can add to functions.php:

function copy_modified_date_field( $post_id, $post ){
    if ( 'project' == $post->post_type ) {
        $now = time();
        update_post_meta( $post_id, 'wpcf-modified-date', $now );
    }
}
add_action( 'save_post', 'copy_modified_date_field', 20, 2 );

Change 'project' to match the slug of this post type, create a custom field called 'modified-date' and associate it with this post type. Let me know if you have questions about this.

#767969

Thank you thats what i did already, i wonder why there is no full date filter for wordpress native fields like published date and modified date.

I feel that i'm duplicating something already there.

#771277

Yes this is a feature that other Users have requested. I will add your vote to this feature request, though I cannot guarantee our developers will decide to implement it in the future. In my opinion it's a reasonable request, so hopefully it will be provided in an upcoming release.

#771396

Great thank you so much.