Skip Navigation

[Resolved] Check specific post meta as condition

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

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 3 replies, has 2 voices.

Last updated by kelvinL-2 3 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#2247653

Dear Sir/Madam,

I know how to show the custom field with specific post id using the item parameter

[types field='task-speaker' item='[types field='todo-task-id' format='FIELD_VALUE'][/types]'][/types]
[php]

How can I apply this in conditions? 

[wpv-conditional if="( $(wpcf-task-speaker-profile-link) ne '' )"]
<a href="[types field='task-speaker-profile-link' output='raw' item='[types field='todo-task-id' format='FIELD_VALUE'][/types]'][/types]">[types field='task-speaker' item='[types field='todo-task-id' format='FIELD_VALUE'][/types]'][/types]</a>
[/wpv-conditional]
#2247837

How can I apply this in conditions?

[wpv-conditional if="( $(wpcf-task-speaker-profile-link) ne '' )"]
<a href="[types field='task-speaker-profile-link' output='raw' item='[types field='todo-task-id' format='FIELD_VALUE'][/types]'][/types]">[types field='task-speaker' item='[types field='todo-task-id' format='FIELD_VALUE'][/types]'][/types]</a>
[/wpv-conditional]
#2248661

Hi,

Thank you for contacting us and I'd be happy to assist.

Since multiple levels of nesting of shortcodes are involved, the conditional statement will not work in this case.

A more efficient and reliable approach to achieve this would be to generate the speaker profile's link, using a custom shortcode:


add_shortcode( 'get_speaker_profile_link', 'get_speaker_profile_link_func');
function get_speaker_profile_link_func()
{
	$todo_task_id = do_shortcode("[types field='todo-task-id' format='FIELD_VALUE'][/types]");
	if (!empty($todo_task_id)) {
		$task_speaker_profile_link = do_shortcode("[types field='task-speaker-profile-link' output='raw' item='".$todo_task_id."'][/types]");
		$task_speaker = do_shortcode("[types field='task-speaker' item='".$todo_task_id."'][/types]");

		if (!empty($task_speaker_profile_link)) {
			return '<a href="'.$task_speaker_profile_link.'">'.$task_speaker.'</a>';
		}
	}
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

This shortcode will only output the speaker profile link, if it exists and you won't need to include any conditional check.

Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

#2251993

My issue is resolved now. Thank you!