Skip Navigation

[Gelöst] Get and modify repeating field data with shortcode

This support ticket is created vor 4 Jahren, 3 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Dieses Thema enthält 1 Antwort, hat 1 Stimme.

Zuletzt aktualisiert von KonstantinS88 vor 4 Jahren, 3 Monaten.

Author
Artikel
#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!