Navigation überspringen

[Gelöst] [wpv-conditional] in Events Manager Form

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:

The [wpv-conditional] shortcode doesn’t work as expected in an Events Manager template. Specifically, the condition comparing [wpv-user field="ID"] with [wpv-post-author format="meta" meta="ID"] doesn't produce output, even though their values are correct.

Solution:

The issue is caused by mixing types of quotes within the conditional statement, which can prematurely close the condition. Ensure you use:

- Double quotes for the if statement.

- Single quotes for the attributes within the shortcodes.

Updated working example:

[wpv-conditional if="( '[wpv-user field='ID']' eq '[wpv-post-author format='meta' meta='ID']' ) OR ( '[wpv-current-user info='role']' eq 'administrator' ) OR ( '[wpv-current-user info='role']' eq 'editor' )"]
<a class="button" href="website">Diese Veranstaltung ändern</a> <br />
[/wpv-conditional]
This support ticket is created vor 4 Monaten, 2 Wochen. 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.

Dieses Thema enthält 6 Antworten, hat 3 Stimmen.

Zuletzt aktualisiert von a.R vor 1 Monat, 2 Wochen.

Assistiert von: Christopher Amirian.

Author
Artikel
#2732345

a.R

Hi 🙂

In an Events Manager Form, this won´t be displayed at all, although we have "Decode Shortcode Content" activated, and "Sanitize shortcode content?" deactivated. [wpv-user field="ID"] and [wpv-post-author format="meta" meta="ID"] have correct results.

	[wpv-conditional if="( '[wpv-user field="ID"]' eq '[wpv-post-author format="meta" meta="ID"]' ) OR ( '[wpv-current-user info="role"]' eq 'administrator' ) OR ( '[wpv-current-user info="role"]' eq 'editor' )"]
	<a class="button" href="<em><u>versteckter Link</u></em>">Diese Veranstaltung ändern</a>	<br>
	[/wpv-conditional]
#2732367

a.R

[wpv-conditional] works, but something seems to be wrong.

[wpv-conditional if="( '[wpv-user field="ID"]' eq '[wpv-post-author format="meta" meta="ID"]' )"]
<p>User is the author of the post.</p>
[/wpv-conditional]

doesn´t work, although the both values are equal.

#2732368

a.R
[wpv-conditional if="1 eq 1"]JAAA[/wpv-conditional]

works.

#2732665

a.R

Maybe I should better call it an Events Manager Template - for a single event - where we want to use this conditional output.

#2732838

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+00:00)

Hi there

When testing conditionals like this, one useful thing to do first is to simply output on the screen the things you are comparing, to confirm that they do output the values you expect in this context.

e.g. just output this to verify

<p>[wpv-user field="ID"] | [wpv-post-author format="meta" meta="ID"]</p>

Next, you can have problems with mixing types of quotes.

If you look at this and read from left to right

[wpv-conditional if="( '[wpv-user field="ID"]' eq '[wpv-post-author format="meta" meta="ID"]' )"]

The if condition begins with the first double-quote, which is looking for the next double-quote to close the if condition. From left to right it finds a double quote at field="ID", closing the if condition prematurely.

Try replacing the double quotes used with the shortcode attributes (field, format, meta) with single quotes.

#2733556

a.R

Hi Nigel, thank you so far.
Yes I´ve looked at the values. They are correct.
Would it REALLY close the condition, after having found ONLY ONE single quote??

#2737113

Christopher Amirian
Supporter

Sprachen: Englisch (English )

Hi,

Sorry for the late reply, using single quotes should do the trick but again make sure you use double quotes only for the If statements and the single quotes for the attributes of the shortcodes.

Thanks.

#2785674

a.R

Ok, thank you.