Skip Navigation

[Resolved] Losing one of my query values when filtering by post type

This support ticket is created 7 years, 11 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 0.95 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 3 replies, has 2 voices.

Last updated by Beda 7 years, 11 months ago.

Assisted by: Beda.

Author
Posts
#381625

I've got a page where I pull up results for a bunch of different custom post types based on a country, which I set via the incoming URL, like this:

hidden link
hidden link

Today I wanted to add a filter to this page so that the visitor could filter results by post type (Post, Publication, Video, etc.)

Filtering by post type doesn't seem to be built-in (correct?) so I followed the instructions in this support thread:

https://toolset.com/forums/topic/creating-a-view-that-filters-by-post-type/

These work great .... *almost*. The problem is that once the visitor changes the post type, the country query filter (specified originally via the URL) is lost.

My question is how do I add a dropdown to filter by post type that doesn't reset my country query?

Thanks!

The dropdown:

[wpv-filter-controls][wpml-string context="wpv-views"]Show: [/wpml-string] [wpv-control url_param="wpv-post-type" type="select" values=",post,publication,video,slideshow" display_values="Everything,News and Blog,Publications,Videos,Slideshows"][/wpv-filter-controls]

functions.php:

function post_type_filter_func( $query_args, $settings, $view_id ) {
    if ( $view_id == 34032 && isset($_GET['wpv-post-type'][0]) && !empty($_GET['wpv-post-type'][0]) ) {
        $query_args['post_type'] = $_GET['wpv-post-type'][0];
    }
    return $query_args;
}
#381726

When you create a View you are asked to select the Post Type that will be handled / queried / returned yb this View.

Filtering by the Post type is not possible natively exactly due to this.

It's not something we intend to provide, as usually, performance concerns will determine that the user selects as few as possible Post types to query.

For a Fully working post type filter as a front end parametric search you would need to select ALL post Types, producing a HUGE and expensive Query with this View.

Anyway, the issue you experience I think I am handling it here:
https://toolset.com/forums/topic/split-parametric-and-display-form-useage-issues/

And I believe it is a BUG.

See, if you set this all up with native Views Features, it still removes the URL Param and just queries by the Parametric Search:

1. Set a view to return Posts by any term or meta, set in the URL parameter
2. Call this View, passing the URL parameter ==> All results are correct
3. If you now in the View have a parametric Search by something else, and use it, it simply removes the passed URL parameter and replaces with the Parametric Search.

This does NOT happen, if the URL parameter is passed by the parametric Search itself.

It ONLY happens, if the filter is NOT preset in the Parametric Search HTML Section.

If you can confirm this I will escalate it as a BUG

I apologize to inform that this will not be solved in the upcoming Views Release.

But we will handle this straight after the next release which will be very soon.

Thank you for your patience and understanding.

#382046

Hi there,

The bug you described sounds exactly like what I'm experiencing. Thanks for confirming it.

As a work-around, can you tell me if it should be possible (and perhaps hint at the method) for me to modify the function I have in functions.php so that the country I've set via the URL (?wpvcountries=Afghanistan) is preserved? I figure since I'm already hacking at this with a function, the function could probably be easily extended to preserve my country selection.

Thanks very much for any help, though I understand this doesn't do anything to address the underlying bug.

#382360

If I understand you correctly, you pass the first (the one you loose) URL parameter just in the Query Section, right?

There is no Parametric Search filter handle somewhere in the Parametric Search HTML editor for this, correct?

In this case, the result is actually expected.

I got a update yesterday from the "bug" I pointed you to, that this is actually not a bug but a new feature, as by now we never passed Query Filter URL Arguments to additional Parametric Search Filter URL Arguments.

We might disagree here wether it's a BUG or a missing feature, but the above "workaround" would implement the same as the fix for it will provide.

You would need to pass the existing URL argument to your Current Code (Query)

You coddle filter the main Query:
https://toolset.com/documentation/user-guides/views-filters/wpv_filter_query/

It seems -unfortunately- that for now you need custom programming work which is beyond the scope of our support.

At this point I would suggest you consider contacting one of our certified partners from this link:
https://toolset.com/consultant/

You will get the custom assistance you need to get on with your project.

Please do not hesitate to open a new thread if other issues or problems arise

Thank you for your patience.

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