Skip Navigation

[Resolved] get published date of post used in post relationship

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to display child post publish date on parent post single page using view's post relationship

Solution:
You should create a view for child CPT and add query filter for this view:

filter by post relationship = Post where this View is shown 

You can find proposed solution with the following reply:
=> https://toolset.com/forums/topic/get-published-date-of-post-used-in-post-relationship/#post-591548

Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/displaying-child-posts/

This support ticket is created 7 years 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 4 replies, has 2 voices.

Last updated by marcB-6 7 years ago.

Assisted by: Minesh.

Author
Posts
#591494

I have used post relationship feature for my 2 custom post types as mentioned below.

1)Lobby
2)Lobby Updates

Lobby Updates are for particular lobby which is defined using post relationship.
For example,
I have added "Lobby 1" in lobby CPT. Now, I am adding "Update 1","Update 2" in Lobby Updates and assigning "Lobby 1" in post relation ship "This Lobby update belongs to Lobby".

Sequence for adding lobby update is,
Update 1
Update 2

so, latest update would be "Update 2". I would like to display published date of recently added Lobby Update in a Lobby Detail page.

In detail page of "Lobby 1" I would like to show published date of "Update 2".

How to achieve above goal?

#591501

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - you should create a view for CPT "Lobby Updates" and add query filter for this view: filter by post relationship = Post where this View is shown and under section "Limit and Offset " select 1 and add [wpv-post-date] to display the published date in loop output editor.

#591540
Screenshot_5.png

Well, I would like to display it in a text.Please check attached screenshot.
So, just for this do I need to create separate view? Is it possible using shortcode?

#591548

Minesh
Supporter

Languages: English (English )

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

Well you have two ways.

1) I already suggested using view
2) you can build custom shortcode to fetch the latest child post. Following code may help you to understand how you fetch child post belongs to particular parent and return the post date value. You can adjust the code as per your need.

$child_args = array(
'post_type' => 'book',
'numberposts' => 1,
'orderby' => 'post_date',
'order' => 'DESC',
'meta_query' => array(array('key' => '_wpcf_belongs_writer_id', 'value' => get_the_ID()))
);
$child_posts = get_posts($child_args);

=> https://toolset.com/documentation/customizing-sites-using-php/displaying-child-posts/

#591566

Thanks. its working