Skip Navigation

[Resolved] Check if child post by current user exists

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

Problem:

I'm trying to make a shortcode that displays the number of child posts of the currently displayed parent post made by the current logged in user. This to hide a Toolset Form after one submission by a user.

Solution:

It doesn't need custom codes within the latest version of Toolset plugins.

You can create a post view with classic editor:

https://toolset.com/forums/topic/check-if-child-post-by-current-user-exists/#post-1514133

Relevant Documentation:

https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items

This support ticket is created 5 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/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by timM-9 5 years ago.

Assisted by: Luo Yang.

Author
Posts
#1513623

Hi!

I'm trying to make a shortcode that displays the number of child posts of the currently displayed parent post made by the current logged in user. This to hide a Toolset Form after one submission by a user.

I saw this topic on the support forums that describes exactly what I would like to achieve: https://toolset.com/forums/topic/conditional-display-of-cred-form-on-post-depending-if-a-child-post-exists/

But unfortunately it's using the old way of quering Toolset Relationships. I read the "How to Migrate Your Site to New Post Relationships" article in the documentation, but can't get it to work.

Can you maybe give me a hint in the right direction how to update this code to be compatible with the new relationships?

Thanks! 🙂

#1514133

Hello,

In your case, it doesn't need custom codes within the latest version of Toolset plugins.

You can create a post view with classic editor:
- Query child posts
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items
- Filter by:
a) Post type relationship filter
b) Select posts with the author the same as the current logged in user.
https://toolset.com/documentation/user-guides/views/filtering-views-query-by-author/

- in section "Loop Editor":
a) within shortcode [wpv-items-found] ... [/wpv-items-found], display text: You have alread created a child post.
a) within shortcode [wpv-no-items-found] ... [/wpv-no-items-found], display the Form's shortcode for creating new child post.

#1514201

Hi Luo, thank you very much. This works great. 🙂