Skip Navigation

[Resolved] Create both buttons and date picker for filter

This support ticket is created 4 years 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.

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 10 replies, has 3 voices.

Last updated by Minesh 4 years ago.

Assisted by: Minesh.

Author
Posts
#2132327

Hi,
Hope you are well.
I have a form with a view displaying custom posts, it has 2 filters currently.
1. Type of post selected from drop-down ie. 1 or 2 or 3
2. Date in post selected with date pickers.

I need to add buttons to quick-filter the Date field. ie. Open Posts and Closed Posts
Basically something like this:
Closed Posts = Between Min_date(01/01/2000) and Max_date(Yesterday)
and
Open Posts = Between Between Min_date(Today) and Max_date(01/01/2100)

Is there a way to do this in a view?

#2133525

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

It will be possible but it will require some custom code and we have to use the View's filter hook "wpv_filter_query" in order to adjust the view's query argument on fly.

If you can share details where on what page with what view you want to implement this I would be happy to share the solution.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) 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.

#2133565

Minesh
Supporter

Languages: English (English )

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

I do not see wp-admin login page. Can you please share the login page link?

#2133655

Hi
It is the standard page:hidden link

#2133659

Minesh
Supporter

Languages: English (English )

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

On that page I'm getting a while page with the message:

Thank you for being patient. We are doing some work on the site and will be back shortly.

I do not see any login form to login to admin.

#2133673

Hi
Sorry, we have disabled the under construction plugin.
It should work now.

#2133729

Minesh
Supporter

Languages: English (English )

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

I see on your site I do not have permission to edit the files that is why I could not able to add custom code snippet at "Custom code" section offered by Toolset:
- hidden link

It shows following messsage:

Unfortunately, this snippet cannot be edited directly. Check file permissions and wp-config.php constants DISALLOW_FILE_EDIT and DISALLOW_FILE_MODS. Alternatively, you can edit the file manually.

Can you please grant me permission so that I should be able to add the "wpf_filter_query" filter.

#2138681

Hi

I have edited the wp-config as requested and tested that the custom code is editable.

I apologize for taking so long to get back to you.

#2138731

Minesh
Supporter

Languages: English (English )

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

Just wanted to double check again that for open and close post I will have to check against the post date or any date custom field?

#2139481

Hi
The field that needs to be checked against is called closing date.

#2141195

Minesh
Supporter

Languages: English (English )

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

I've added the following filter code that will help you to filter by Close and Open radio button to the "Custom Code" section offered by Toolset.
=> hidden link

add_filter('wpv_filter_query','func_filter_view_by_open_close',10,3);

function func_filter_view_by_open_close($query_args, $settings, $view_id){
    if($view_id == 6265){
      
     
      
     $all_args = $_REQUEST['search']['dps_general'];
     foreach($all_args as $k=>$v):
      	if($v['name']=='wpv-options' and $v['value']=='closed'){
          
           $start = strtotime("01-01-2000");
     	  $end = strtotime("yesterday");
          
           $between = $start.",".$end;
      
      $query_args['meta_query'][] = array(  
                    'key'=> 'wpcf-closing-date',
                    'value' => $between,
                    'type' => 'NUMERIC',
                    'compare' => 'BETWEEN');
          
        }else if($v['name']=='wpv-options' and $v['value']=='open'){
           $start = strtotime("today");
     	  $query_args['meta_query'][] = array(  
                    'key'=> 'wpcf-closing-date',
                    'value' => $start,
                    'type' => 'NUMERIC',
                    'compare' => '>');
          
        }
     endforeach;
     
       
    }
    return $query_args;
}

=> hidden link