Hi,
i would have a shortcode that repeats all fields of Date to sort or show Parent of rfg in slider etc.
But my Shortcode-function will only show always the first field of slug "datum-und-uhrzeit" in rfg group "termine-veranst" of rfg.
this is shortcode which works in view
[insert_metadata postidmy="[wpv-post-id]"]
i provide at: lien caché (output is on screenshot red rectangle)
This is the code for the Shortcode in my functions.php:
function myownfunc( $atts ) {
$post_id = $atts['postidmy'];
$fieldvalues = toolset_get_related_posts( get_the_ID(), "termine-veranst", array( 'query_by_role' => 'parent', 'return' => 'post_object'));
foreach ($fieldvalues as $fieldvalue) {
$partone = types_render_field('datum-und-uhrzeit', array('post_id' => $fieldvalue->ID));
return $partone;
}
}
add_shortcode( 'insert_metadata', 'myownfunc' );
can you help me?
thx - alex

Minesh
Supporter
Les langues:
Anglais (English )
Fuseau horaire:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
When you use return statement the control of the function will return and will not loop though. To loop through every iteration we will require to store the values to array.
Can you please try to use the following code:
function myownfunc( $atts ) {
$post_id = $atts['postidmy'];
$fieldvalues = toolset_get_related_posts( get_the_ID(), "termine-veranst", array( 'query_by_role' => 'parent', 'return' => 'post_object'));
$temp = array();
foreach ($fieldvalues as $fieldvalue) {
$partone = types_render_field('datum-und-uhrzeit', array('post_id' => $fieldvalue->ID));
$temp[] = $partone;
return "<li>".join("</li><li>",$temp)."</li>";
}
}
add_shortcode( 'insert_metadata', 'myownfunc' );
Hi Minesh,
thx for your rapid answer. But it is only show one date. - in rfg are two dates stored:
see in Screenshot.
thx alex
Hi Minesh,
all good - i moved return outside of foreach-loop. - it works!
function myownfunc( $atts ) {
$post_id = $atts['postidmy'];
$fieldvalues = toolset_get_related_posts( get_the_ID(), "termine-veranst", array( 'query_by_role' => 'parent', 'return' => 'post_object'));
$temp = array();
foreach ($fieldvalues as $fieldvalue) {
$partone = types_render_field('datum-und-uhrzeit', array('post_id' => $fieldvalue->ID));
$temp[] = $partone;
}
return "<li>".join("</li><li>",$temp)."</li>";
}
add_shortcode( 'insert_metadata', 'myownfunc' );
thx - alex

Minesh
Supporter
Les langues:
Anglais (English )
Fuseau horaire:
Asia/Kolkata (GMT+05:30)
Great - you are welcome to mark resolve this ticket 🙂
My issue is resolved now. Thank you!
Hey Minesh,
one thing about the datum-und-uhrzeit field in rfg.
1. why doesnt it show the time? I used date and time in rfg field
2. can i compare it to actual date and time -> if it in paste i would remove it
thx - alex

Minesh
Supporter
Les langues:
Anglais (English )
Fuseau horaire:
Asia/Kolkata (GMT+05:30)
As per our support policy we entertain only one question per ticket. This will help other users searching on the forum as well as help us to write correct problem resolution summery.
Can you please close this ticket and I'll split the ticket with your new question.

Minesh
Supporter
Les langues:
Anglais (English )
Fuseau horaire:
Asia/Kolkata (GMT+05:30)
You are welcome to mark resolve this ticket.