Skip Navigation

[Resolved] Use of the Shortcode View is disabling the filtering function

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

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 20 replies, has 2 voices.

Last updated by joshM-4 6 years, 11 months ago.

Assisted by: Shane.

Author
Posts
#524383
Screen Shot 2017-05-15 at 12.42.21 PM.png
Screen Shot 2017-05-15 at 12.38.48 PM.png

I am trying to: display different parent categories on specific pages, and allow filtering of those child categories on that page

I visited this URL: hidden link

I expected to see: AJAX sorting of the products when I click on any of the categories listed there

Instead, I got: no sorting when I click on one of the listed categories

This view was set up using the shortcode to display the content, but I noticed after adjusting some of the filters in the "Filter Editor" it had changed itself to be filtered by the URL instead of the Shortcode. It has changed itself several times after I've corrected it back to the shortcode.

The filtering has worked randomly under both filter settings but then will simply stop working. I don't know if I don't understand something or if it's a bug but it's frustrating that it changes itself on it's own.

I'm hoping you can help me out.

Thanks.

#524432

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi JOsh,

Thank you for contacting our support forum.

I'm not quite sure what you are trying to achieve here. Is it that you want to filter your view based on a shortcode value or are you using frontend filters to filter you view .

Please let me know.

Thanks,
Shane

#524476

Hi Shane,

If I click on a category like "T Shirts" (or any category) at the top of hidden link it should immediately filter the results to show only the T-Shirts. Right now it filters nothing. It used to work until Toolset automatically changed my filter settings from being based on the shortcode to being based on the url of the page. Once I noticed this I set the filter settings back to using the shortcode, but now the filtering no longer works.

I want it to work when I use the shortcode. Right now when I use the shortcode the filtering doesn't work. I hope that is more clear.

Thanks for your help.

#524482

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Josh,

So essentially you want the view to be able to be filtered by a shortcode parameter and url parameter for the same filter correct?

Frontend filters uses the URL Parameters and prefiltering the view uses a shortcode parameter.

This is actually possible with one of our view filters if this is what you want to achieve.

Please let me know.
Thanks,
Shane

#524805

Hi Shane,

As I understand it, yes that is what I'm trying to do. Please let me know how to configure the view filter to achieve this.

Thanks for your help.

#524830

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Josh,

In this case you will need to use this hook in the link below.
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_custom_field_filter_original_value

This will allow you to re-use your view with shortcode params as substitute for the url params.

Please let me know if this helps.
Thanks,
Shane

#524853

Thanks Shane, it looks like that will work. Unfortunately my php skills aren't so great which is why I bought Toolset. Is there any way you could give me a little more help? I'm just wanting to sort by the product categories and only display the categories that have products in them.

I realize it's not your role to write this for me, but maybe you have a sample of this use case somewhere that you could share?

#524868

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Josh,

Would you mind providing me with admin access to the website so that I can have a more detailed look at your setup ?

This hook is meant to be used when you want to re-use a view on another page.

If that is the case then we can proceed if not then it would be easier to create a duplicate view and change how the filtering works or is it that you want the view to be pre-filtered.

I'm not sure i'm understanding 100% clearly and wouldn't want us to go down the path of an incorrect solution 🙂

Looking forward to hearing from you soon.
Thanks,
Shane

#524935

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Josh,

Ok an example would be this below.

/*
Let's reuse a View with a filter by a Types custom field that gets the field value using a URL parameter. We want to use this View on a page that will not get that URL parameter, but still we want to filter the View by a value set on a shortcode attribute in the {{wpv-view}} shortcode.
We can asume that out View has an ID equal to 25 and the custom field is [php]my-post-field

(so its real slug is

wpcf-my-post-field

). Likewise, let's say that the View is filtering by the custom field

my-post-field

using the URL parameter

my-field-param

and that we want to pass the value of the fied using the shortcode attribute

myvalue

, like in {{wpv-view myvalue="xxx"}}.
We are going to find the string

URL_PARAM(my-field-param)

and replace it with

VIEW_PARAM(myvalue)

:
*/
add_filter( 'wpv_filter_custom_field_filter_original_value', 'prefix_change_url_to_shortcode_attribute', 10, 3 );
function prefix_change_url_to_shortcode_attribute( $value, $key, $view_id ) {
// We might need to add a check so this filter only gets applied if we are in the specific page where we want to reuse the View: use is_single(), is_page() or is_singular()

if ( is_page(332) && $view_id == 302 && $key == 'wpvproductcat' ) { // if we are displaying our View with ID 302 and the filter is for the field with name wpcf-post-date-filter
$value = str_replace( 'URL_PARAM(wpvproductcat)', 'VIEW_PARAM(category)', $value );
}
return $value;
}
[/php]

So if you add this to your functions.php file then you can re-use the view.

If you call the view on a separate page like this page here hidden link

If you add a parameter to the view [wpv-view name="products-display-main-category" view_display="layout" category='my-cat-slug']

Replace my-cat-slug with the slug of a category and the view will filter.

Please let me know if this helps.
Thanks,
Shane

#524947

Thanks Shane,

I've been working on this for an hour trying to make sense of it but for some reason I just haven't been able to make it work. I inserted the function into my functions.php and tried it with the updated shortcode ( [wpv-view name="products-display-main-category" view_display="layout" category="guys"] ) on the /contact/ page just to try it but it's only showing the product grid.

I'd be happy to provide FTP credentials if you want to access the child theme and see if I've not understood the function properly. I have multiple backups online and offline so there's no risk of messing anything up.

I really appreciate all of your help.

#524951

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Josh,

I see the issue. It seems the code I added wasn't added to the forum correctly.

You can add the ftp credentials to the private fields below.

Thanks,
Shane

#525276

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Josh,

I took another look at the hook at it and this hook only works for custom fields. Since we don't have a hook that can handle this I would recommend creating a clone of the view and set that view to filter by shortcode attribute.

You will only need to create 1 duplicate and not a duplicate for each category.

Please let me know if this helps.
Thanks,
Shane

#525284

Thanks for taking a closer look Shane.

I'm sorry this is taking so much work. Can you help me understand how duplicating this view will resolve the situation? I'm having a hard time connecting the dots. I duplicated the view, set the filter to be by shortcode, but when I view it the filtering still isn't working. What am I missing?

I put the new view on hidden link to test it.

#525291

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Josh,

No worries lets start with this one. So for this view on the contact page, will the filters still be used? Or will the page already have a pre-filtered list of products

Please let me know.
Thanks,
Shane

#525301

For the view on the contact page, it should use the filters you see there, but it is also already being filtered by the parent category that is defined in the shortcode - [wpv-view name="products-display-main-category-shortcode" category="guys"]

So it is both, as I understand it. It's only showing products within the parent category of "Guys." That parent category has the following children categories: Caps, Collared Shirts, Hats, Jackets, Pants, Sweatshirts, and T Shirts (as you can see when you visit the page - if you don't see them you may need to do a hard-refresh). I would like the view to perform additional filtering when one of these child categories is clicked on, but right now it's not.

So that's where we are on the view in the contact page. Hopefully that helped.

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