Problem:
On a post archive or a view that lists posts of custom post type, such that:
-Posts Can (but do not have to be) children of the other post type.
-Posts with parents should have a link to the parent, posts without parents should not have such link.
The issue: if no parent is assigned, a random link to Parent CPT is displayed.
Solution:
Use wpv-if to evaluate if the CPT has a parent (Check the documentation).
If it returns true, the link will be displayed, on false, it won't.
Example:
-Problem:
--I need to check if each post int the loop has a parent post of type "Teams".Teams custom post slug is "teams"
-Solution:
--Use the "wpv-if" to check if the post has parent(s)
--Use the "_wpcf_belongs_{parent-slug}_id" to get the teams that the post belongs to them and assign it to a variable in the same condition like this (teams="_wpcf_belongs_teams_id").
--Check if the list of teams is empty using the "empty" function like this "empty($teams)".
[wpv-if teams="_wpcf_belongs_teams_id" condition="false" evaluate="empty($teams)"][wpv-post-link id="$teams"][/wpv-if]
Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/#checking-post-parent
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 |
---|---|---|---|---|---|---|
- | - | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 |
- | - | - | - | - | - | - |
Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)
This topic contains 2 replies, has 2 voices.
Last updated by amberH 8 years, 7 months ago.
Assisted by: Beda.