Skip Navigation

[Resolved] Shortcode attribute with ampersand and/or spaces not working

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

Problem: I'm trying to pass a Types field value into a View's Query Filter using a shortcode attribute, but it's not working as expected.

Solution: Be sure to use output="raw" in the Types field shortcode, otherwise some extra formatting may be added.

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

Last updated by roulartaM 5 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1359793
view-child.png
template-parent.png

Hi support! I have a page with news articles where I want to display all related newsarticles. I've made a custom post type so I didn't use the default post type.

In the parent content template (template-parent.png), I've set a shortcode attribute that gets the current category. In the child view (view-child.png), I filter the results on that shortcode attribute.

3 on 4 shortcodes do work (see hidden link).
But the 4th isn't working at all: no related newsitems are queried (see hidden link).

I guess it's because it contains one ampersand and/or multiple (space).
Could that be a correct guess? How can I solve this?

#1359853

In the parent content template (template-parent.png), I've set a shortcode attribute that gets the current category.
Where? I don't see anything related to categories in this screenshot. I see a Types field shortcode related to the inspiration field, but nothing related to categories, taxonomies or terms.

I guess it's because it contains one ampersand and/or multiple (space).
Could that be a correct guess?

I don't think it has anything to do with ampersand or spaces. You should definitely use output='raw' in the Types field shortcode you have nested in the inspiration attribute, like this:

[wpv-view name="nieuwsartikels-gerelateerd" inspiration="[types field='inspiration' output='raw'][/types]"]

If that doesn't solve the problem, please add some extra debugging information in the Content Template so I can see the value of the inspiration field:

Inspiration: [types field='inspiration' output='raw'][/types]<br />
[wpv-view name="nieuwsartikels-gerelateerd" inspiration="[types field='inspiration' output='raw'][/types]"]

Then show me a screenshot of a niewsartikel post in wp-admin that has a matching inspiration field.

#1360261

Great! Adding output='raw' did the trick, very happy with that simple solution. Thanks a lot Christian!