Skip Navigation

[Resuelto] Get and modify repeating field data with shortcode

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

Este tema contiene 1 respuesta, tiene 1 mensaje.

Última actualización por KonstantinS88 hace 4 años, 3 meses.

Autor
Mensajes
#1762529
data.JPG

I have a repeating field "contact" where people input data in the following format

"firstname lastname | info@example.com"

Now I want to have a shortcode that gets the array with the data and checks if there is a "|" symbol and if yes it outputs the data in another format.

function func_contacts($atts) {
	global $post;

$contact = get_post_meta( $post->ID, 'wpcf-' . 'contacts' , true );	

foreach ($contact as &$value) {
		if ( strpos($value, "|") )	{
			$subarray = explode('|', $value);
			$conty .= $subarray [0] . " E-Mail: " . $subarray [1] . "<br>"; 
		} else {
			$conty .= $value."<br>"; 
		}
	}

return $conty;
}
add_shortcode( 'show-contact-data', 'func_contacts' );

$contact seems to not be an array and contain only the first instance of the repeating field.

I am lost.

None of the docs here helped me with retrieving data from repeating fields:
https://toolset.com/documentation/programmer-reference/views-api/#render_view
https://toolset.com/forums/topic/how-to-display-repeatable-field-groups-with-php/
https://toolset.com/documentation/customizing-sites-using-php/displaying-repeating-fields-one-kind/

#1762541

I just had to change the first line from:

$contact = get_post_meta( $post->ID, 'wpcf-' . 'contacts' , true );

to

$contact = get_post_meta( $post->ID, 'wpcf-' . 'contacts' , false );

To retrieve more than one instance. Silly me.

My issue is resolved now. Thank you!