Skip Navigation

[Resolved] Compare a URL Field in HTML conditional

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

Problem:
How to compare a URL field value in HTML conditional?

Solution:
You need to compare the "Raw" value of the Field.
And example:

[wpv-conditional if="( '[types field='tickets-url' output='raw' id='$tour-events'][/types]' ne '' )"]
<a href="[types field='tickets-url' output='raw' id='$tour-events'][/types]">Get Tickets</a>
[/wpv-conditional]

The above example also shows how to use a Field of a parent Post of the Current used post.

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 7 years, 9 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by mikes-23 7 years, 9 months ago.

Assisted by: Beda.

Author
Posts
#429259

I am trying to check if a parent post field has data before outputting a link. Based on another answer I read in the forum I came up with this:

[wpv-conditional if=" '[types field="tickets-url" id="$tour-events"][/types]' ne '' "]
                   <a href="[types field='tickets-url' output='raw' id='$tour-events'][/types]">Get Tickets</a>
[/wpv-conditional]

$tour-events is the parent type and tickets-url is field I want to check. The code above doesn't work. I am able to output the values without the conditional but the conditional check is never evaluating to true.

Can someone correct my syntax please?

#429374

Please use the GUI to construct your conditionals.

You will then also need to edit the Fields you use, since the Conditional GUI does not have an advanced mode to edit those Fields.

That will give you this code:

[wpv-conditional if="( $([types field='single-line' id='$toolset-custom'][/types]) eq 'value' )"]
  content to display
[/wpv-conditional]

If that does not work, try this:

[wpv-conditional if="( '[types field='single-line' id='$toolset-custom'][/types]' eq 'value' )"]
  content to display
[/wpv-conditional]
#429501

How can I use the GUI to construct these? I do not see any options for selecting parent field in the GUI.

As per your examples I tried:

[wpv-conditional if="( $([types field='tickets-url' id='$tour-events'][/types]) ne '' )"]
  content to display
[/wpv-conditional]

And

[wpv-conditional if="( '[types field='tickets-url' id='$tour-events'][/types]' ne '' )"]
  content to display
[/wpv-conditional]

Neither work

#429503

You create the Conditional with the "Conditional Display" GUI.

Then, you insert it.

After, you highlight the Post Field and hit on "Fields and Views"

There you search for the field and choose the Display Options.
If there is a Parent/Child Relation, it will let you choose the correct Parent.

I must ask, do you have apostrophes saved in those Post Fields (value)?

If so, it will not work, this is a known bug.

Can you output the Field of the parent itself?

What does it output if it holds a value?

#429541

There are no apostrophes. The value is a validated URL field. Using this shortcode it outputs fine:

[types field='tickets-url' output='raw' id='$tour-events'][/types]

I am unable to get the conditional to check if it has a value. Any ideas?

#429545

I would need to request temporary access (WP-Admin and FTP) to your site
- preferably to a test site where the problem has been replicated if possible -
in order to be of better help and check if some configurations might need to be changed

Your next answer will be private which means only you and I have access to it.

❌ Please backup your database and website ❌

✙ I would, if possible, need access to a site where only a minimal set of Plugins and a default theme is active.
This to avoid eventual compatibility issues with other software.

✙ I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site.
This is also a reason the backup is really important

✙ Please add the Links to:

- The Views Edit Screen

- The Page/Post where you insert the View

- The corresponding Post, and it's Field

#429969

It would have been nice to point me to the Post Type which we relate to.

Since you gave your Post type "tour-events" different Title I first assumed it woudl not even exist.

To fix this I needed to compare against the "raw" value of that Field.

This is the code that works:

[wpv-conditional if="( '[types field='tickets-url' output='raw' id='$tour-events'][/types]' ne '' )"]<a href="[types field='tickets-url' output='raw' id='$tour-events'][/types]">Get Tickets</a>[/wpv-conditional]
#430105

ok

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