Saltar navegación

[Resuelto] Conditional on PHP shortcode

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
Conditional display based on custom field value using PHP

Solution:
You can use the Types PHP API function types_render_field() to get value of custom field.

You can find proposed solution in this case with the following reply:
https://toolset.com/forums/topic/conditional-on-php-shortcode/#post-2314245

Relevant Documentation:
- https://toolset.com/documentation/customizing-sites-using-php/functions/
- https://toolset.com/documentation/customizing-sites-using-php/

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

Zona horaria del colaborador: Asia/Kolkata (GMT+05:30)

Este tema contiene 5 respuestas, tiene 2 mensajes.

Última actualización por Paulo Ramalho 4 years, 3 months ago.

Asistido por: Minesh.

Autor
Mensajes
#2314219

Hi all.
I have a Crew CPT and on the single member page I have some custom fields for the RRSS links.

enlace oculto

I'm trying to put here some conditional when the field is empty the icon do not appear on front end.
I've searching the documentation but not find it.

Thanks in advance.

#2314245

Minesh
Colaborador

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You can use the Types PHP API function types_render_field() to get value of custom field.

<?php 

global $post;

$value = types_render_field('twitter',array('output'=>'raw')); 
if(!empty($value)) {

?>
<em><u>enlace oculto</u></em>
<?php 
}
?>

You can adjust the above code as required.

More info:
- https://toolset.com/documentation/customizing-sites-using-php/functions/
- https://toolset.com/documentation/customizing-sites-using-php/

#2316117

Hi Minesh.
Great, It works very well. Thank you very much man.
Now I just have to figuer out how to put another fields in the same code, to not repeat the entire code for different fields.
Thanks again.

#2316123

Minesh
Colaborador

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

If your goal is to not the display the field with link if it does not contain any value then you have to repeate that code and replace the custom field names where applicable.

#2316637

Yes, I've done it. But I'm seeing how to use less code. My PHP knowledgment is not so good.
Thanks a lot Minesh, the problem is resolved.

#2316641

Minesh was very very effective. Thanks again. My issue is resolved now. Thank you!