Skip Navigation

[Resolved] wpv-attribute in view not working as expected.

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to use an attribute applied to a parent View shortcode inside a nested child View shortcode.

Solution: Apply the same attribute to both View shortcodes to pass information down the hierarchy.

Relevant Documentation:
https://toolset.com/documentation/user-guides/passing-arguments-to-views

This support ticket is created 5 years, 6 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
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 5 replies, has 2 voices.

Last updated by Sammut 5 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#1123889

I have a view that is working fine when I add the id amanually:

[wpv-view name="get-course-price-for-cta" courseid="12335"]

I also have an attribute that is working fine to pull in an ID:

[wpv-attribute name='course-id']

However, when combined, the view breaks:

[wpv-view name="get-course-price-for-cta" courseid="[wpv-attribute name='course-id']"]

Is what I am doing not valid?

Thank you!

#1124042

Hi, first I would not use "course-id" and "courseid" because it's confusing. Are these typos? Are they the same attribute? Why are they different?

Second, a lot of this depends on how you have your Views nested, and where the courseid and course-id attributes are applied. For example, let's say you have a custom Page with a View. Nested inside the Loop of that View, you have another View.
In the Page:

[wpv-view name="Your Parent View" courseid="999" locationid="123"]

In the Parent View Loop:

[wpv-view name="Your Child View" courseid="[wpv-attribute name='courseid']"]
Parent Course: [wpv-attribute name='courseid'], Parent Location: [wpv-attribute name='locationid']

Output of the Parent View: Parent Course: 999, Parent Location: 123

In the Child View Loop:

Child Course: [wpv-attribute name="courseid"], Child Location: [wpv-attribute name="locationid"]

Output in child view: Child Course: 999, Child Location:

Location is empty in the Child View, because the locationid attribute applied to the parent View shortcode is not automatically inherited by the Child View. It must be added to the Child View shortcode in order to access that value in the Child View. So I can't really tell based on your description why things aren't working as expected - I'm not able to see the hierarchy of Views to know which attributes should be inherited. To get a better understanding, I would need to see how this is all structured in wp-admin. I will activate private reply fields here so you can share login credentials, if you would like. Let me know where I can see this on the front-end of your site.

#1124589

Thank you. The parent view is as follows:

[wpv-view name="content-block" blockid="34126" course-title="[wpv-post-title output='sanitize']" course-id="[wpv-post-id]"]

The output for this view uses the attribute to append a URL, e.g.,

<a href="/checkout?edd_action=add_to_cart&download_id=[wpv-attribute name='course-id']" class="button" style="width:100% !important;">

and it works great.

So now within this Parent View we have a child view. The child view simply looks at a CPT and queries on the POST ID to pull out a price.

[wpv-view name="get-course-price-for-cta" ctacourseid="XXXX"]

Since this Child View is simply doing a direct query, I am not sure how it is related to the parent view and if the attribute

[wpv-attribute name='course-id']

works in the Parent View why would it fail when inserted in the Child View?

Thank you!

#1124650

The child View does not have a shortcode attribute course-id, it only has ctacourseid. The course-id value is not "inherited" automatically. You should be able to place the wpv-attribute shortcode instead of "XXXX", like this:

[wpv-view name="get-course-price-for-cta" ctacourseid="[wpv-attribute name='course-id']"]

The Child View's post ID Query Filter must be set up to respond to a shortcode attribute ctacourseid. Inside the child View, you can access the course ID like this:

Value of original course-id value: [wpv-attribute name='ctacourseid']
#1124654

Thanks, yes, that is exactly what I have:

[wpv-view name="get-course-price-for-cta" ctacourseid="[wpv-attribute name='course-id']"]

The resulting output is:

<! --- View not found -->
"]

However, if I manually enter in a ctacourseid the view works perfectly.

#1124774
Screen Shot 2018-10-10 at 1.09.58 PM.png

Try deleting the hyphen from the course-id attributes and attribute shortcodes. Only lowercase letters and numbers should be used in these attributes, as I was just reminded while trying to test a Query Filter (see the screenshot).

[wpv-view name="content-block" blockid="34126" course-title="[wpv-post-title output='sanitize']" courseid="[wpv-post-id]"]
[wpv-view name="get-course-price-for-cta" ctacourseid="[wpv-attribute name='courseid']"]

If this isn't working, I'll need some more context. If you provide login credentials, I can take a look in your wp-admin panel. Private reply fields are active here.

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