Skip Navigation

[Resolved] Passing a dynamic argument to a Toolset view shortcode

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

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by quincyS 4 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#1684783
Screen Shot 2020-07-02 at 4.54.37 PM.png

Tell us what you are trying to do?
I have a view that displays a list of posts and I want to filter the view based on the taxonomy from the page where it is listed.

For example, the view returns a list of courses (MCAT, ACT, SAT, etc) and I want the view to filter automatically based on a specific taxonomy from the page where it is viewed (MCAT page shows MCAT courses, etc). The page and courses are different post types and use different taxonomies, but the taxonomy terms are the same (so an MCAT course uses 'course-location=mcat' and an MCAT page uses 'page-category=mcat')

The static view shortcode currently looks like this: [wpv-view name='favorite-school-courses' wpvcoursecategory="mcat"] and works perfectly - the issue is that I need to change the category for each page I publish.

The goal is to make the "mcat" portion dynamic according to a taxonomy on the page where the view is seen.

I believe I can nest 2 shortcodes in order to do this and ended up with the following:
[wpv-view name='favorite-school-courses' wpvcoursecategory='[wpv-post-taxonomy type="page-category" format="name"]

When tested, this returns all courses without filtering.

On their own, both pieces function correctly - [wpv-post-taxonomy type="page-category" format="name"] returns the current page taxonomy when tested solo but will not work when nested in the original view code.

Is there any documentation that you are following?
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-type
https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/
https://toolset.com/forums/topic/nested-shortcodes-in-views/

Is there a similar example that we can see?
hidden link - this MCAT courses displayed on an MCAT page, but done statically.

What is the link to your site?
hidden link

#1685595

Shane
Supporter

Languages: English (English )

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

Hi Quincy,

Thank you for getting in touch.

It is true that you are able to filter the view by a shortcode parameter. You have the right concept below here

[wpv-view name='favorite-school-courses' wpvcoursecategory='[wpv-post-taxonomy type="page-category" format="name"]

However you need specify that the [wpv-post-taxonomy] shortcode gets the slugs rather than the name.


[wpv-view name='favorite-school-courses' wpvcoursecategory='[wpv-post-taxonomy type="page-category" format="slug"]

Please try this and let me know if this helps.
Thanks,
Shane

#1685839
Screen Shot 2020-07-03 at 8.43.47 AM.png

Hi Shane - thanks for the prompt reply.

Unfortunately, this didn't resolve it - the code is still returning courses unfiltered. Both pieces still work independently but don't filter any of the returned courses.

The screenshot shows the result - it's all courses sorted by date, hence the mixed categories.

#1686767

Shane
Supporter

Languages: English (English )

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

Hi Quincy,

Could you add this to your view and let me know if it is returning the correct values inside the view.

[wpv-attribute name="wpvcoursecategory"]

This should let you know if your taxonomy shortcode is passing the correct values to your view.

Please try this and let me know if the correct values are being returning.

Thanks,
Shane

#1687261

Ok, interesting, it seems like the taxonomy code is not working when nested but works on its own.

When using the static attribute

[wpv-view name='favorite-school-courses' wpvcoursecategory="mcat"]

Im able to get the wpv-attribute-name to display correctly in view output.

Im also able to get the dynamic attribute

[wpv-post-taxonomy type="page-category" format="slug"]

to work on it's own, but it will not function when nested in the original view code nor will the wpv-attribute-name display anything.

#1688935

Shane
Supporter

Languages: English (English )

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

Hi Quincy,

To help speed this up, would you mind allowing me to have admin access to the site to check on this for you ?

The private fields will be enabled for your next response.
This is the link you are using to test it correct? hidden link

Thanks,
Shane

#1690169

Shane
Supporter

Languages: English (English )

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

Hi Quincy,

The issue seems to be with the shortcode block that elementor has. Its breaking whenever you try to use a nested shortcode.

I was able to workaround this by using a text editor widget instead and add the same shortcode to it.

Please let me know if this helps.
Thanks,
Shane

#1690825

That did it - my issue is resolved now. Thank you!