Skip Navigation

[Resolved] shortcode of rfg datum-und-uhrzeit only have 1 entry

This support ticket is created 2 years, 9 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 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 8 replies, has 2 voices.

Last updated by Minesh 2 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#2108315
Bildschirmfoto 2021-07-07 um 11.43.35.jpg

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: hidden link (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

#2108327

Minesh
Supporter

Languages: English (English )

Timezone: 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' );
#2108341
Bildschirmfoto 2021-07-07 um 12.07.32.jpg

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

#2108353

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

#2108355

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Great - you are welcome to mark resolve this ticket 🙂

#2108357

My issue is resolved now. Thank you!

#2108359

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

#2108371

Minesh
Supporter

Languages: English (English )

Timezone: 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.

#2108991

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You are welcome to mark resolve this ticket.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.