Skip Navigation

[Resolved] Identifying orphaned posts

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

Last updated by Waqar 3 years ago.

Assisted by: Waqar.

Author
Posts
#2029997

I am hoping to better understanding of the new database tables and relationship functions to identify orphaned children.

We have two post types in a one to many relationship... Podcasts and Episodes.

Can you please let me know what functions or queries to use to identify...

1) Episodes that are not related to any "parent" Podcast

2) Episodes that ARE related to a "parent" Podcast, but that podcast is not in publish status

3) Episodes that WERE related to a "parent" Podcast, but that podcast has been deleted / the parent ID no longer exists

Thank you for any help here.

#2030571

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

To programmatically, get the information about the related parent or child posts in a post-relationship, you can use the "toolset_get_related_posts" function:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

For example, to loop through all the posts from a specific post type, you can use the "get_posts" function
https://developer.wordpress.org/reference/functions/get_posts/

And then inside the loop, you can use the "toolset_get_related_posts" function to retrieve each post's, related parent or child posts.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2030741

Hi there -

Appreciate the reply but I'm not sure it really addresses any of the three scenarios I'm specifically trying to identify, especially scenario 1 and 3.

1) Episodes that are not related to any "parent" Podcast

2) Episodes that ARE related to a "parent" Podcast, but that podcast is not in publish status

3) Episodes that WERE related to a "parent" Podcast, but that podcast has been deleted / the parent ID no longer exists

Hoping you could please provide a little more detail about to query for these specific scenarios.

Thank you,
Todd

#2033939

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

I'm afraid, we don't have copy-paste code snippets available for these exact requirements, but if you need more personalized assistance using the functions from my last reply, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

If your goal is to create a visual list of posts from those scenarios, you can alternatively use Views, which won't require custom code.

1) Episodes that are not related to any "parent" Podcast

You can create a new post view that shows the "Episodes" posts.

At this point, this view will show all the "Episodes" posts, and to limit the results only to those without any parent "Podcasts" post, you can wrap the output of the individual loop item content in a conditional check like this:


<wpv-loop>
	[wpv-conditional if="( '[wpv-post-id item="@podcast-episode.parent"]' eq '' )"]
	.......
	[/wpv-conditional]
</wpv-loop>

For "Episodes" posts without any parent "Podcasts" post, the parent ID "[wpv-post-id item="@podcast-episode.parent"]" shortcode will be empty.
( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/ )

Note: Please replace "podcast-episode" with the actual slug of the post-relationship on your website.

The final result would be that only posts without any parent posts will show on the front-end.

Guide on using conditional output:
https://toolset.com/documentation/legacy-features/views-plugin/using-shortcodes-in-conditions/

2) Episodes that ARE related to a "parent" Podcast, but that podcast is not in publish status

You'll create a post view that shows the "Episodes" posts, same as the last case, however, the conditional check would be different:


<wpv-loop>
	[wpv-conditional if="( '[wpv-post-id item="@podcast-episode.parent"]' ne '' ) AND ( '[wpv-post-status item="@podcast-episode.parent"]' ne 'publish' )"]
	.......
	[/wpv-conditional]
</wpv-loop>

It will only show those "Episodes" posts that have a parent "Podcast", but that parent's status is not "publish".

3) Episodes that WERE related to a "parent" Podcast, but that podcast has been deleted / the parent ID no longer exists

When a parent "Podcast" post will be properly deleted, Toolset will automatically delete the relevant associations with the child "Episodes" too. Based, on this, I'm not sure if you need a separate list for this scenario.

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