Skip Navigation

[Résolu] Conditional display: wpv_contains

This support ticket is created Il y a 6 années. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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)

This topic contains 3 réponses, has 3 voix.

Last updated by Shane Il y a 6 années.

Assisted by: Shane.

Auteur
Publications
#686310

This site requires an iframe, but at present the source is http only and WordPress doesn't display the content. The iframe URL is being added to the Page via an ACF field.

I am anticipating that at some point in the future, perhaps soon due to the upcoming Chrome 68 update, that the source site will be served as https.

What I'm trying to do is conditionally display either a link to the external site if the URL in the ACF field starts with http, but display the iframe if the ACF field starts with https. This way, when the URL becomes https at some point in the future the iframe can be displayed immediately without the client having to have me make changes in the layout.

Based upon other support tickets I have seen, I'm thinking it looks something like this, but this isn't working...

[wpv-conditional if="( wpv_contains('https','$(hannah_url)') ne '0' )"][iframe src="[wpv-post-field name='hannah_url']" width="100%" height="500"][/wpv-conditional]

I am using the IFRAME plugin (https://wordpress.org/plugins/iframe/) to enable the iframe shortcode. It works outside of the conditional statement as long as the URL is https.

#687218

Hi,

Thanks for contacting support.

To achieve what you're looking for, add this function to your theme's functions.php file (backup first, it's always a good idea)

function wpv_contains($haystack, $needle)
{
  $pos = strpos($haystack, $needle);
  if($pos !== true){
    return false;
  }
}

Add the function name in Toolset -> Settings -> Front-end Content -> Functions inside conditional evaluations.

Finally, in your view you add this conditional:

[wpv-conditional if="( wpv_contains('[types field='hannah_url' output='raw'][/types]','https') eq false )"][iframe src="[wpv-post-field name='hannah_url']" width="100%" height="500"][/wpv-conditional]

Let me know if that helps,
Ricardo

#687651

Ricardo,

Thanks for the reply. Unfortunately that does not seem to work.

I added the function wpv_contains, which I didn't have in place originally. It's also added in Toolset -> Settings -> Front-end Content -> Functions inside conditional evaluations. However, the conditional statement displays the iframe in all cases (whether or not the hannah_url field is http or https.)

I tried several variations of the conditional statement, using various syntax...

1. wpv-post-field in the conditional statement instead of types field.
2. reversing the order of the 'https' and the 'field'
3. Stating true instead of false
4. Using ne '0' instead of false or true

In each of these cases, either the iframe displayed (or didn't display if the syntax was otherwise incorrect) whether or not the field was http or https.

#697898

Shane
Supporter

Languages: Anglais (English )

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

Hello,

I'll be taking care of this ticket now.

Looking at this it seems that we need to debug and see whats happening in the conditional shortcode.

Could you enable the debug for the shortcode by adding the debug = 'true' attribute. View the page on the frontend and provide a screenshot of the debug information so that I can have a look.

Thanks,
Shane

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