Skip Navigation

[Resolved] Custom shortcode breaking loop

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

Problem: I have a Content Template that appears to stop working when I add some content, like a custom shortcode.

Solution: There is a known issue with conditionals that contain a large amount of content, and it has become evident in some versions of PHP 7. There are a few options here, in order of ease of implementation:

1. Simplify your conditionals so the amount of content in any one conditional tag is much smaller. This may mean reorganizing code to use multiple content templates, or creating custom shortcodes to break up large amounts of content into smaller chunks.

2. Edit your site's php.ini file (this may have to be done by your host company) to include the line

pcre.jit= 0

This may bypass the issue in PHP 7, as described here: https://stackoverflow.com/questions/39685883/php-preg-jit-stacklimit-error-inefficient-regex

3. Downgrade to PHP 5.6

Relevant Documentation:
https://toolset.com/forums/topic/conflict-with-php7-and-avada-theme/page/2/#post-595850

This support ticket is created 6 years, 8 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 jeanB 6 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#623066
shortcodenotworking.png
shortcodeworking.png
shortcodeloop.png
shortcode.png
registeredshortcode.png
loopeditor.png

** This example is using the view named: OVERNATNING but is the same on all views **

I am trying to:
I have a few custom shortcodes in my Loop Item template. They all work fine, but when I try to add this one, for some reason it breaks my loops. I have deleted all of the functionality in my shortcode to test it, so my shortcode is just the following.

function get_primary_cat() {
return 'test';
}

If you remove the shortcode from line 27, the loop items all work fine!

Link to a page where the issue can be seen:
hidden link

hidden link

The Edit View page:
hidden link

I expected to see:
The post titles and data to come through for each post. It works for some, not for others?

Instead, I got:
It seems to be using the page's title instead and the listing data is missing?

#623095

Okay I see that there is quite a lot of complex content in this Content Template. Let's try to narrow down the issue. Please duplicate the current Content Template from Toolset > Content Templates, to keep as a backup. Then edit the current Content Template so that only this code remains:

[wpv-post-title]<br />
[get_primary_cat], [wpv-post-field name="phone"]

Then test the page again. If the phone numbers do not appear as expected, then we can be fairly sure the rest of the template is not causing a conflict. Please let me know the results. If you need to replace the original content from the duplicate content template that's fine.

#623112

Hi Christian,

You're right - this seems to work fine when it's stripped to just:

[wpv-post-title]<br />
[get_primary_cat], [wpv-post-field name="phone"]

I'm not sure what's going on, or why adding this one line would break the loop. 🙁
It is a complicated view, but otherwise works beautifully until I add that shortcode, even though it's not really doing anything other than returning 'test'.

Thanks for looking at it - I'm really stuck 🙁

#623114

Hi Christian,
It works perfectly fine, if I take the <div class="business-actions"> section out or if I take the <div class="listing-actions"> out!?
I don't suppose the loop content is too long or something?

#623122

Okay here is an explanation of what I think is happening, assuming there are no other errors in your Content Template:
https://toolset.com/forums/topic/conflict-with-php7-and-avada-theme/page/2/#post-595850

Basically there is a problem with conditionals that contain a large amount of content, and it has become evident in some versions of PHP 7. There are a few options here, in order of ease of implementation:
1. Simplify your conditionals so the amount of content in any one conditional tag is much smaller. This may mean reorganizing code to use multiple content templates, or creating custom shortcodes to break up large amounts of content into smaller chunks.

2. Edit your site's php.ini file (this may have to be done by your host company) to include the line

pcre.jit= 0

This may bypass the issue in PHP 7, as described here: https://stackoverflow.com/questions/39685883/php-preg-jit-stacklimit-error-inefficient-regex

3. Downgrade to PHP 5.6

Let me know your thoughts and we can go from there.

#623251

Gotcha, okay - thanks Christian! I've split a block of the content out into another template and then included that & it works perfectly.

That's probably a better way for me to do it anyway, considering the number of view pages that I will have, I can share some content between them instead.

Thanks so much for your help - I'm glad I wasn't going completely mad (yet) 🙂