Skip Navigation

[Closed] Filter results in a view using a cookie like the slug of a CPT in relationship.

This support ticket is created 3 years, 10 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9: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: Africa/Casablanca (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by Jamal 3 years, 10 months ago.

Assisted by: Jamal.

Author
Posts
#1646889

I have saved in the cookie of my website which "unit" he previously selected, but I need to filter in the views, results of the relationships of many to many that have been configured.

There are several cases, but as in "differentials" that has "who recommends" and for each "unit" there are different results or even some equal to another "unit".

How can I display in the view only the results for the "unit" stored in the current cookie?

#1647393

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello and thank you for contacting the Toolset support.

I am not very sure to understand your request, but I'll give it a try. Please correct me or provide more details, if you feel that I am answering the wrong question.

Toolset does not support a way to pull/use a cookie inside view query filters, but on the other hand, you can pass a value to a view as a shortcode argument, read more about it here https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes

That way, you can build your own shortcode that will pass the cookie value to the view. The code would be similar to:

[wpv-view name="my-view-name" cookievalue="[my-cookie-value-shortcode]"]

Read more about creating shortcodes on these articles:
- https://codex.wordpress.org/Shortcode_API
- hidden link

I hope this helps. Let me know if you have any questions.

#1647643

Great, by the shortcode I had already gone ahead and created one to return the value of "unit", but now how do I use the view filter with this value to list only the posts related to "unit"?
It is a relationship from many to many, as a "post" can have several "units" or even a "unit" can have several "posts".

#1647659

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

You can create a query filter on the relationship and then pass the element to it with the shortcode. Maybe this article can help a bit https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items

Please note, that currently, a view can only be filtered by ONE relationship. If you need to use multiple relationships, you may need to use some custom code. Check the relationship API here https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

If it does not, please allow me temporary access to check your view closely and see what can be done or not. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

#1648605

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Thank you for the access credentials and for the details. But, I still need some more details to understand the view and how you are using it.
Check this screenshot hidden link The view is directly used with an Elementor widget. This means that we cannot pass any value(cookie value) as a shortcode argument. We should insert the views with an Elementor shortcode or text module.

On the other hand, the view is not using any filter, this means that it will return all the results. Check this screenshot hidden link

I could not find you custom shortcode either, can you add a screenshot of where it is added? I expected it to be used as an argument for the view shortcode. Can you give me more details about it?

I, also, was not able to visit hidden link always redirected to the homepage. I am not sure what is blocking me right now, but I can't really test with this page.

Finally, I wanted to run a test on a separate page, but I do not have test data to work with. I will need to know a step-by-step explanation of what you want to achieve:
1. User visit ...
2. Clicks on ...
3. Selects ...
4. I expect to have ...
5. Instead, I got ...

The topic ‘[Closed] Filter results in a view using a cookie like the slug of a CPT in relationship.’ is closed to new replies.