Skip Navigation

[Resolved] Querying and Displaying Child Posts -> Date Field entry for continional output

This support ticket is created 7 years, 11 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
- 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 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: Africa/Cairo (GMT+02:00)

This topic contains 4 replies, has 2 voices.

Last updated by Ahmed Hussein 7 years, 11 months ago.

Assisted by: Ahmed Hussein.

Author
Posts
#397103

PLI

I am trying to: check if parent entry has child elemets, if yes get custom wp types field "termin-von" and conditionally output a text like (request now) if the "termin-von" date is after today.

I visited this URL:
- https://toolset.com/forums/topic/how-to-display-the-child-value-in-a-parent-list-view/
- https://toolset.com/documentation/user-guides/querying-and-displaying-child-posts/

I expected to see: get custom field entry from child element

Instead, I got: nothing

- i have added the custom shortcode [child-exists]

- functions.php snippet:

// wp-types check if parent has child elements
// https://toolset.com/forums/topic/how-to-display-the-child-value-in-a-parent-list-view/
function child_exists_func( $atts ){
$child_posts = types_child_posts('termine');
	if ($child_posts) {
	//return true;

		foreach ($child_posts as $child_post) {
		  //echo $child_post->wpcf-termin-von;
		  return $child_post->wpcf-termin-von;
		}
	}
}
add_shortcode( 'child-exists', 'child_exists_func' );

- Loop item in view:

[wpv-conditional if="( '[child-exists]' gt 'TODAY()' )"]text here[/wpv-conditional]
#397391

Hi, Thanks for contacting Toolset support forums.

If I understand correctly you may need to change your code to this:

function child_exists_func( $atts ){
$child_posts = types_child_posts('termine');
    if ($child_posts) {
        return types_render_field( "wpcf-termin-von", array("post_id" => $child_posts[0]->ID) );
    }
}
add_shortcode( 'child-exists', 'child_exists_func' );

The code above assumes your parent post only has one child, which is the one you're willing to apply the condition on. types_render_field renders the field value and returns it, you can read more about it here: https://toolset.com/documentation/user-guides/displaying-wordpress-custom-fields/

Please let me know if that solves your problem.

Cheers!

#397445

PLI

Hi, thanks for your feedback.

- The parent post can have one or more child posts.
- if the parent post has child post/s and the custom datefield "termin-von" of one or more of the child posts is in the future, i will output nothing in the view
- if the parent has no child post/s or one or more of the child post custom datefield "termin-von" is today or in the past, i will output a text like "request now".

Can you please update the snippet?

is it better to make this condition in the php snippet oder in the view with a [wpv-conditional]?

#397454

PLI
bildungsakadem_69.jpg

here is a screenshot of the view output for better understanding

#397560

Hi,

Thanks for your reply. In order to achieve what you've described above, you'll need to calculate the timestamp of a date field, and create a shortcode for the calculation result and use it within the wpv-conditional shortcode.

If you need help to achieve this you may contact one of our certified partners, and they'll be more than happy to help you, for more info please refer to this link: https://toolset.com/consultant/

Cheers!

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