Navigation überspringen

[Gelöst] Display repeated group field

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:

The issue here is that the user is using the new field groups option in our Toolset Beta plugins and wanted to display the repeated groups on the frontend.

Solution:

I spoke with the development team and they said that they are working on an API for the repeatable field groups but its not quite ready as yet.

So for now we are not able to display this on the frontend.

The solution I provided was for the old method of repeatable field groups but given that you are using the Beta we currently don't have a solution for it just as yet.

This support ticket is created vor 6 Jahren, 10 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Dieses Thema enthält 8 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von hellobarrio vor 6 Jahren, 7 Monaten.

Assistiert von: Shane.

Author
Artikel
#614275
Schermata 2018-02-08 alle 16.09.01.png

Hi,
I trying the new version (version 2.3-b2 ), how I can display the repeated group field with php?

thanks

#614444

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hello,

Thank you for contacting our support forum.

Actually yes you can do it with php.

Take a look at the link below and let me know if this helps.
https://toolset.com/documentation/user-guides/creating-groups-of-repeating-fields-using-fields-tables/#using-types-php-api-to-display-repeating-fields-groups

Thanks,
Shane

#614594

Thanks, it work; I used this code:

$args = array('post_type' => 'gruppo-paragrafo', 'orderby' => 'meta_value', 'order' => 'ASC');
$query = new WP_Query( $args );

if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();

echo types_render_field("titolo");

}
}

But this code display every group field "gruppo-paragrafo" i created in every page. How I can display only the group field "gruppo-paragrafo" created for the single page?

thanks

#614662

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hello,

I see so you decided to just use the wordpress main query function.

In order for it to display the information for the current post you need to query the post parent meta field.

For e.g

'meta_query' => array(array('key' => '_wpcf_belongs_writer_id', 'value' => get_the_ID()))

From the example above I provided the _wpcf_belongs_writer_id as the meta query value to query to parent information. In this case its for a Writers CPT where the slug of that cpt is writer, so what you need to do is to substitute your slug into the code.

Your format should be _wpcf_belongs_{myparentcptslug}_id

Please let me know if this helps.
Thanks,
Shane

#614799
Schermata 2018-02-10 alle 11.13.07.png

Hi, I tried '_wpcf_belongs_page_id' but it's not working...

This is the link of the frontpage: versteckter Link

The slug of the page is: azienda

Now, I use this code

$args = array(
'post_type' => 'gruppo-paragrafo',
'numberposts' => -1,
'meta_key' => 'wpcf-genre',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(array('key' => '_wpcf_belongs_azienda_id', 'value' => get_the_ID()))
);
$child_posts = get_posts($args);
foreach ( $child_posts as $post ) {
	setup_postdata( $post );
	
	echo types_render_field("numero");
	
	wp_reset_postdata();
}

I also read this post: https://toolset.com/forums/topic/problem-with-wpcf-belongs-to-a-page/, is it the same problem?

thanks

#614802

Instead, using this code

$child_args = array(
'post_type' => 'gruppo-paragrafo',
'numberposts' => -1,
'meta_key' => 'wpcf-genre',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(array('key' => '_wpcf_belongs_azienda_id', 'value' => get_the_ID()))
);
$child_posts = get_posts($child_args);

print_r($child_posts);

The array is empty. Why?

Thank you

#615262

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hello,

That is strange as it should return some posts if the post page has children.

Would you mind allowing me to have a look at your cpt setup on the backend? Also please let me know which posts are the parent and child and where was this code added.

The private fields will be enabled for your next response.

Thanks,
Shane

#615359

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi,

I see and I checked on this and it seems that there isn't a way to display this completely as yet.

I spoke with the development team and they said that they are working on an API for the repeatable field groups but its not quite ready as yet.

So for now we are not able to display this on the frontend.

The solution I provided was for the old method of repeatable field groups but given that you are using the Beta we currently don't have a solution for it just as yet.

Thanks,
Shane

#902390

Hi...
I do not understand if the new version of toolset (the paid version) has already been released...

Can we take a test before proceeding with the purchase?

tnx