Skip Navigation

[Resuelto] Conditional code based on field value of a parent post type not working?

This support ticket is created hace 6 años, 6 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Este tema contiene 4 respuestas, tiene 2 mensajes.

Última actualización por aaronM-9 hace 6 años, 6 meses.

Asistido por: Shane.

Autor
Mensajes
#748400
temp2.jpg
temp.jpg

I'm using the new version of Toolst Forms (v2.0) and I can't seem to get a conditional statement to work. This was working before, but I'm not sure if the reason it's stopped working is because of the upgrade or because of something else, and I'm at a bit of a loss.

I have a post type called Ads, where the user sets the wpcf-ad-type to either "Offering" or "Seeking". Inside the Ad single page, it runs a view that displays all the responses to the ad, showing post type Ad-Response entries that are children of Ad. The line of code that isn't working is the "if wpcf-ad-type eq 'Seeking'" line below.

What's strange is that this line (added for troubleshooting purposes):

"[types field="ad-type" id="$ad"][/types]"

Correctly displays the HTML "Seeking" on the view. However, anything in this line:

[wpv-conditional if="( $(wpcf-ad-type).id(ad) eq 'Seeking' )"]
    <p>[types field='ad-response-seller'][/types]</p>
[/wpv-conditional]

Does not appear on the page. Here is the full code of the view:

	[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop>
          <p><strong>[wpv-post-author format="meta" meta="first_name"] [wpv-post-author format="meta" meta="last_name"] ([wpv-post-date format="j F Y, g:i a"])</strong></p>
          <div class="conversation-left-speaker">"[types field="ad-type" id="$ad"][/types]"
          	[wpv-conditional if="( $(wpcf-ad-type).id(ad) eq 'Offering' )"]
            	<p>[types field='ad-response-buyer'][/types]</p>
            [/wpv-conditional]
          	[wpv-conditional if="( $(wpcf-ad-type).id(ad) eq 'Seeking' )"]
            	<p>[types field='ad-response-seller'][/types]</p>
            [/wpv-conditional]
            [wpv-conditional if="( $(wpcf-ad-response-privacy) eq 'Public' ) OR ( '[wpv-post-author format="meta" meta="ID" id="$ad"]' eq '[wpv-post-author format="meta" meta="ID"]' ) OR ( '[wpv-post-author format="meta" meta="ID" id="$ad"]' eq '[wpv-user field="ID"]' )"]
            	<p>[types field='ad-response-text'][/types]</p>
            [/wpv-conditional]
          </div>
          [wpv-view name="view-ads-responses-02-replyoption" adid="[wpv-post-id id="$ad"]" parentpostid="[wpv-post-id]" responseid="[wpv-post-id]"]
		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]

Appreciate any help. Cheers.

- Aaron

#749299

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Aaron,

Thank you for contacting our support forum.

Would you mind providing me with access to the website and this page so that I can debug and see whats up here ?

Thanks,
Shane

#749462

Sure, no problem. Can you send me a reply that allows me to respond privately? Also, please be advised I have modified the code since the original post. I managed to get that specific example working by referencing fields in the post without needing to reference the parent post type. However, if you look further down to the following code in the same view, you will see that when referencing fields in the parent post type, these do not work properly (i.e. "wpcf-ad-type.id"). It seems any time I try to build a conditional statement using fields from the parent post type, it fails to work.

			[wpv-conditional if="( $(wpcf-ad-type).id(ad) eq 'Offering' ) AND ( '[wpv-post-author format="meta" meta="ID" id="$ad"]' eq '[wpv-user field="ID"]' )"]
				<p><a href="JavaScript:be_changevisibility('reply[wpv-attribute name="responseid"]')">Reply</a></p>
				<div id="reply[wpv-post-id id="[wpv-attribute name="responseid"]"]" style="display:none">[cred_form form="form-ad-response-seller"]</div>
			[/wpv-conditional]
#752369

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Aaron,

I've enabled the private fields.

Thanks,
Shane

#774394

I was able to solve the issue on my own by replacing any of the conditional statements referencing parent types with shortcodes (in lieu of $ variables). Thanks for the help.

- Aaron