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]
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]
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
My issue is resolved now. Thank you!