Skip Navigation

[Gelöst] Conditional – check if specific child posts do not exist

This support ticket is created vor 7 Jahren. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 4 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Matthias Reichl vor 7 Jahren.

Assistiert von: Minesh.

Author
Artikel
#592231

* Tell us what you are trying to do?

I have the follwing custom post types
- event (parent)
- person (parent)
- registration (child of 2 parents)

In a loop listing the events I want to show a link to a CRED form for regitration only if:
the person is not yet registered.
I fetch the ID of the person of the logged-in user with a custom function [get_person_id]

I suppose that I need a custom function to check this condition, however, failed to establish a working one.

* Is there any documentation that you are following?

I searched the Toolset form but found only examples with a single parent-child relation.

#592353

Minesh
Supporter

Sprachen: Englisch (English )

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

Hello. Thank you for contacting the Toolset support.

As I understand, you just need to check if user is logged in or not, as user will be loggedin if and only if he registered. correct?
If yes:

You can try following code to display conditional content.

[wpv-conditional if="('[wpv-current-user info='id']' eq  '')"]
user is NOT registered
[/wpv-conditional]

[wpv-conditional if="('[wpv-current-user info='id']' ne  '')"]
user is  registered
[/wpv-conditional]

Please have look at following documentation that may help you:
=> https://toolset.com/documentation/views-shortcodes/#wpv-current-user
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

#592363

Hi Minseh!

Thank you for your answer, however, this is not quite my problem.

The problem is to check whether the logged in user is already registered to an event.
Conditon = there is NO record in the custom post type "registration" with

- parent 1 = the event (the condition will be placed in the view listing all events)
- parent 2 = the person associated with the logged in user = custom function [get_person_id]

#592370

Minesh
Supporter

Sprachen: Englisch (English )

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

Ok - that means you need to check if registration (child) post is exists for any event equal to currently logged in user. I would like to make here clear user can register for multiple events - correct? so we need to check with particular event if current user registered.

So, here is the Doc to fetch related child posts:
=> https://toolset.com/documentation/user-guides/querying-and-displaying-child-posts/
=> https://toolset.com/documentation/customizing-sites-using-php/displaying-child-posts/

The best way is:
- create a view for your post type registration - lets say view name "display-registration-button"
- Add query filter (need to add two filters):
#) Post relationship filter = post set by parent view
#) post author = same as loggedin user
(More info: https://toolset.com/documentation/user-guides/filtering-views-query-by-author/)
- Add your registration button to this view's loop output section and save the view
- Add view "display-registration-button" in a loop listing the events

I hope this will solve the issue.

#592728

Hi Minesh!

Thank you for your assistance.