Skip Navigation

[Resolved] script with toolset shortcodes

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

Problem:

How to avoid conversion of quotation marks into HTML entities, when used in a Views output.

Solution:

Suggested to either:

1. Include suppress_filters="true" attribute in the "wpv-post-body" shortcode


[wpv-post-body view_template="slug-of-the-content-template" suppress_filters="true"]

OR

2. Skip the use of "wpv-post-body" shortcode and include the loop item's content directly in "wpv-loop" tag:


<wpv-loop>
 .....
</wpv-loop>

Relevant Documentation:

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-body

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

Our next available supporter will start replying to tickets in about 0.92 hours from now. Thank you for your understanding.

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: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Ido Angel 5 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#1341665

I am using jQuery autocomplete to link to an anchor in the page. The anchor is an ID of a custom post type, "Question".
Basically, the code is this:

  $(function() {
    var availableTags = [
      { href: "#spencer",
                 label: "Spencer Kline"
               },
               { href: "#bond",
                 label: "James Bond"
               },
    ];
    $("#tags").autocomplete({
      source: availableTags,
        select: function( event, ui ) { 
            window.location.href = ui.item.href;
            }
    });
  });

But I have many "questions" and I don't want to write millions of available tags manually, so I was thinking of using the view's loop to run this automatically.

What I did was, I places the non repeating parts of the code before and after "<wpv-loop"> like this:

[wpv-layout-start]
     <script>
    $(function() {
    var availableTags = [
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<wpv-loop>
		[wpv-post-body view_template="loop-item-in-questions-code"]
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
    ];
    $("#tags").autocomplete({
      source: availableTags,
        select: function( event, ui ) { 
            window.location.href = ui.item.href;
            }
    });
  });
      </script>
[wpv-layout-end]

And the source part of the code, which I need to repeat, I placed inside the look like this:

{href:"#[wpv-post-id]",label: "[wpv-post-title]"},

The output, technically, is working - except that I think the square brackets are breaking something and making the quote marks (") look like this:


    $(function() {
    var availableTags = [
	
	
	
		{href:& quot;#12& quot;,label: & quot;שאלה שתיים& quot;},
	
		{href:& quot;#11& quot;,label: & quot;שאלה אחת& quot;},
	
	
	
	
    ];
    $("#tags").autocomplete({
      source: availableTags,
        select: function( event, ui ) { 
            window.location.href = ui.item.href;
            }
    });
  });
      

the " mark is replaced with & quot ; (no spaces, I placed spaces here so it doesn't turn automatically to "), and there are unneeded line spaces ...which makes the code not work, of course.

Is there any smart way to get around this?

Thanks!

#1341915

Hi Ido,

Thanks for asking! I'd be happy to help.

To overcome this character conversion/escaping, you can follow any of these two approaches:

1. You can introduce suppress_filters="true" attribute in the "wpv-post-body" shortcode:
( ref: https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-body )


[wpv-post-body view_template="loop-item-in-questions-code" suppress_filters="true"]

OR

2. You can skip the use of "wpv-post-body" shortcode and include the loop item's content directly in "wpv-loop" tag:


<wpv-loop>
		{href:"#[wpv-post-id]",label: "[wpv-post-title]"},
</wpv-loop>

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1341929

Perfect, Waqar! Thanks 🙂 If we meet one day I buy you a beer for all the help 🙂