Skip Navigation

[Gelöst] How to pass URL parameter to the view for filtering

This support ticket is created vor 4 Jahre, 5 Monate. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. 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)

This topic contains 3 Antworten, has 2 Stimmen.

Last updated by Christian Cox vor 4 Jahre, 5 Monate.

Assisted by: Christian Cox.

Author
Artikel
#1358981

Tell us what you are trying to do?

I have created a view and some filters.
I have a custom date field and I want to provide users a dropdown select to filter "past posts" or "upcoming posts" (based on my custom date and today).

I found in similar questions that I should use "wpv_filter_query". My problem is that I cannot pass the value of selected dropdown as a param to catch it later in "wpv_filter_query".
Here is the select inside the [wpv-filter-controls]:

<select class="js-wpv-filter-trigger form-control" name="date-check">
<option value="" selected>-- All --</option>
<option value="past posts">past posts</option>
<option value="upcoming posts">upcoming posts</option>
</select>

Is there any documentation that you are following?
https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/
https://toolset.com/documentation/user-guides/views-filters/#wpv_filter_query

Is there a similar example that we can see?
https://toolset.com/forums/topic/query-filter-by-month-using-url-parameter/
https://toolset.com/forums/topic/date-range-filter-custom-field-checkboxes/
https://toolset.com/forums/topic/wpv-control-postmeta-comma-separated-list-of-option-values/

What is the link to your site?
I can provide you if needed

#1359187

Hi, you should be able to find the selected option value in the $_GET superglobal with the key 'date-check'. Here's an example:


add_filter( 'wpv_filter_query', 'extra_filtration', 10, 3 );
function extra_filtration ( $query, $view_settings, $view_id ) {
  $views = array( 123, 456, 83 );
  if( in_array( $view_id, $views) ) {
    // uncomment next line to dump everything in $_GET to the logs
    // error_log( print_r( $_GET, true) );
    $date_check = $_GET['date-check']; // $date_check now equals "upcoming posts" or "past posts" or ""
    error_log('date check: ' . $date_check );
    // do $query manipulation here
  }
 return $query;
}

Change 123, 456 to be a comma-separated list of View IDs where you want to apply this filter.

#1359205

Hi Christian, thank you for your response but my problem is when I hit search button the 'date-check' is not passed on URL hence $_GET['date-check'] is null in `wpv_filter_query`.
Thanks

#1359235

Can you tell me more about this View?
- Are you using AJAX for search or for pagination? If you disable AJAX, can you find the generic search field in $_GET?
- Is the advanced search option "Only show available options for each input" turned on?
- Are any other URL parameters passed into the $_GET superglobal correctly by other filters?
- Are the search filters and search results displayed on separate pages, or the same page?
- Have you inserted the View using separate blocks in the block editor, or separate shortcodes in the classic editor?
- Can I see the View on your live site somewhere? If so, please provide a URL.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.