Skip Navigation

[Resolved] Get Parent post title to Export in XML Feed

This support ticket is created 6 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by NattapatP8602 6 years ago.

Assisted by: Waqar.

Author
Posts
#1133810

In short:
1. Need post relationship "Title" in order to export in XML value. So I don't need to switch to Taxonomy.
2. Need to auto connect the "Listing" with all the upper parent.
(Choose Sub-district > Auto connect with Province )
(Choose Project > Auto connect with Developer )

Hi, toolset team
I'm trying to make a custom post type and post fields to fit with the XML export process.
The site is Real Estate Site
Export Custom fields and Taxonomy value is Okay.
However, the Relationship Post Type is not in the option to choose.

My custom post types(relationship):
Province - (1 to many of the lower)
[District(1 to 1)Post Code] - (1 to many of the lower)
Sub-district - (1 to many of the lower)
Developer - (1 to many of the lower)
Project - (1 to many of the lower)
Listing

Every type are the parent of "Listing"

The questions are.

1.Wp all export pro allow you to write php and take the result as a value to return.
So, I think about How to get the parent post "Title" and return the value in PHP function.

2.In the backend that you can connect all the post relationship together, If I chose only Sub-district as a parent of "Listing".
Will it auto connect to the "District" and "Province" that the chosen "Sub- district" belong to. If not, how can I achieve it?.

If I cannot achieve both of this question , I have to quit using Post Relationship.
And the taxonomy will be the only option.

Because you can directly choose to export or import the value.
Life will be so easy.
However, it would be suck because you will lose the relationship of all the things and it don't make sense at all.

Please help me get through this.

#1134179

Hi there,

Thanks for asking! I'd be happy to help.

1. You can get the title (or any other information) from the related posts, using "Post Relationships API".

Specifically, you can use the function "toolset_get_related_posts" for this:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

This will allow you to query either child or parent posts from the specified relationship. We have more details with usage examples, in these guides:
https://toolset.com/documentation/customizing-sites-using-php/displaying-child-posts/
https://toolset.com/documentation/customizing-sites-using-php/displaying-parent-posts/

2. Toolset post relationships can directly connect only two post types (e.g. "A" post type can be connected to "B" post type).

But indirect relationships can be formed, through connecting one post type from a relationship, to a different one (e.g. "A" post type connects to "B" and then "B" post type connects with "C" post type and so on).

As you mentioned, you're already using this approach for connecting "Provinces" all the way down to "Listings", which is the right and only way to achieve this, using post relationships.

It won't be possible to get information about a connected "province", directly from a listing, but you'll be able to get them one level at a time. This also means that no relationship level can be skipped, i.e. a "Sub-district" cannot be set as a direct parent of a "Listing".

If for some reason this setup of post-relationships isn't feasible, then an alternative would be to go with a flatter and single dimension taxonomy-posts connections.

I hope this helps.

regards,
Waqar

#1134826

Got it!
I made the function to return location name bse on relationship slug that the function call.

<?php
function get_place_title($relationship_slug){
// Get the ID of the parent post, which belongs to the "place" post type
$place_id = toolset_get_related_post( get_the_ID(), $relationship_slug, 'parent' );
// Get all the parent (place) post data
$place_post = get_post( $place_id );
 
// Get the title of the parent (place) post
$place_name = $place_post->post_name;
// Get the contents of the parent (place post
$place_content = $place_post->post_content;

	return "$place_name";
}
?>

Thank you for the support
I have to learn a lot of php to make this work, lol.