Skip Navigation

[Resolved] filter for post date range

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 12 replies, has 3 voices.

Last updated by judeH-2 1 year, 11 months ago.

Assisted by: Minesh.

Author
Posts
#2529923
Screen Shot 2023-01-08 at 10.03.12 PM.png

Tell us what you are trying to do?
Is there a way to provide user a filter to select posts published from date_1 mm-dd-yyyy to date_2 mm-dd-yyyy? I only see a single field in filter not a range

#2530267

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot 2023-01-09 at 12.55.51.png

Hi there

When you insert a filter for a date field, choose "between" for the comparison setting and it will provide two inputs (for the "from" and "to" inputs).

#2530365
no-post-date.jpg

Actually there is no post-date in the Add Search Field or Custom Search Filter options. See screenshot.

#2530941

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Nigel or we assume that you want to add the frontend filter for the custom date field.

It seems that you want to add the frontend filter for the default post date field - is that correct? If yes:
- You can not add the frontend filter for default post date field. The workaround would be you should add a custom date field "default-post-date" and when you save/update post copy the default post date field value to this custom date field and then later add the frontend filter for the "default-post-date" field.

#2532973

MInesh,

Thanks for the suggestion. I did as you suggested, the between is an option now. More questions:

1) Both labels are publish-date. Can I change the first label to "From" and the second one to "To"? I don't see an option on the right side to let me give different labels.
2) As mentioned in the other ticket, the filters have no effect on hidden link. Not sure what I have done wrong.
3) I don't see options on the right side let me bold my labels or specify more padding/margins between filters.

Thanks for your help.

--Jude

#2532999

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

1) Both labels are publish-date. Can I change the first label to "From" and the second one to "To"? I don't see an option on the right side to let me give different labels.
==>
To change the label you should click on the label itself and change the text and to make it bold you should press CTRL+b.

2) As mentioned in the other ticket, the filters have no effect on hidden link. Not sure what I have done wrong.
==>
What you mean by not have effect. Do you want to display it as test or date-picker. If you want to display it as date picker then you should select the "Datepicker" from "Type of control" select box. Can you please clarify what exactly is not working.

3) I don't see options on the right side let me bold my labels or specify more padding/margins between filters.
==>
There must be - I'm not sure why you do not see those.

if you do not know how to do it please send me what you want to filter with what and admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2533615

Can Minesh or Nigel get back to me on this issue?

#2533663

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

The thing is that you can add the frontend filters for the custom field that is belongs to post type you set your view to query. I see that you set your view to query default post type "post" but there is no custom field assigned to this post type.

On investigating this further I found that you assigned the publish date filter to post type "Developments". More over the filter will work when the custom field "publish-date" will have value.

I'm checking if I can offer you any other workaround. Please hold on for further updates.

#2533677

Minesh,

Thanks for the update. I am new to Toolset, and still learning it, especially the concept of custom fields. Some settings maybe left from me playing with it and can be removed.

The date filter for post type "Developments" should be removed. The publish-date range should be a selectable field in the frontend by typing MM/DD/YYYY, and the display area should also allow sorting articles by publish date in ascending or descending order.

Hope this clarifies my intention.

Thanks again.

#2533769

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now: hidden link

I've added the following filter "wpv_filter_query" to "custom code" section offered by Toolset:

add_filter( 'wpv_filter_query', 'func_filter_by_post_date', 10, 3 );
function func_filter_by_post_date( $query_args, $view_settings, $views_id  ) {
  
  
    if ( $views_id == 12931 and isset($_REQUEST['wpv_filter_submit'])) { 
          
          $qargs = $query_args['meta_query'];
      
    	
          
      foreach($qargs as $k=>$v):
      
      				
                   if($v['key']=='wpcf-publish-date' and $v['value']!=''){
                            
                     $between_values = explode(",",$v['value']);
                    
                     $start_date = explode("/",$between_values[0]);
                     
                     $end_date =  explode("/",$between_values[1]);
                     
                                    
                     $query_args['date_query']  = array(array(
                                              'before' => array(
                                                  'year'  => $end_date[2],
                                                  'month' => $end_date[0],
                                                  'day'   => $end_date[1],
                                              ),
                                              'after' => array(
                                                  'year'  => $start_date[2],
                                                  'month' => $start_date[0],
                                                  'day'   => $start_date[1],
                                              ),
                                              'inclusive' => true,
                                          ),
                                      );
                    
                       if(isset($query_args['meta_query'][$k])) {
                                   unset($query_args['meta_query'][$k]); 
                        }
                    break;
                            
                   }
      				
          endforeach;
   			
      
    }
    return $query_args;
}

This is the max customization I can offer and the other filters you will have to move before the "Update" button.

If you can share FTP access details I can see if I'm able to apply the ajax otherwise you will have to go with full page refresh for all the filters.

#2536793

Hi Minesh,

I really appreciate all your help. Everything works well. All links under Browse (hidden link => Browse) now use the new page with the correct filtering and proper styling, and they are simplified to one page - "Search & Blog Listing" with different parameters.

One question I have for you: I would like to have the sitewide search from the top nav results to the same page, i.e. if someone enters a phrase in the top search box, the result should be in the same format.

In TT3 templates, there is one called Search. If you use this link hidden link, you can see how it works now. But if I use the view we build for "Search & Blog Listing", how can I get the search phrase "horowitz" also fills the left side text search field?

Thanks for your help.

--Jude

#2536801

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Glad to know that the solution I shared help you to resolve your original issue reported with this ticket.

May I kindly ask you to open a new ticket for every new question you may have. This will help other users searching on the forum as well as help us to write correct problem resolution summery for the original issue reported with this ticket.

Thank you for understanding.

#2537183

My issue is resolved now. Thank you!

I will open a new ticket for the followup questions.