Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.
Problem:
Conditional output based on child post
Solution:
To display conditional content based on the child posts with pre-Types 3.X.X, you need to use custom shortcode with [wpv-conditional] shortcode.
I have a postype "objet" which is parent from a postype "wishlist"
In the "objet" content template, I need to define a conditional output based on the following statement :
- a child "wishlist" post exist for the displayed objet
- it has the same author than the current logged in user
Can you help on this as I have not been able to find the right way to make it!
Thanks
Pat
Hello. Thank you for contacting the Toolset support.
Well - you can use following shortcode to check if any child post exists for your currently displayed parent.
Add following shortcode to your current theme's functions.php file:
function func_child_post_exists( $atts ){
global $post;
return toolset_get_related_post( $post->ID, 'state-city','child');
}
add_shortcode( 'child-post-exists', 'func_child_post_exists' );
Where:
- Replace 'state-city' with your post -relationship slug.
Now, call the function as given under:
[wpv-conditional if="( '[child-post-exists]' eq '0' )"]
no child post available
[/wpv-conditional]
[wpv-conditional if="( '[child-post-exists]' ne '0' )"]
Yes - yes child post available
[/wpv-conditional]
Where:
- Register shortcode name child-post-exists at :
=> Tooset => Settings => Front-end Content => Third-party shortcode arguments
Now, regarding your another query, do you want to check that post author is same as loggedin user?
Thanks for your support.
I have tried your solution and the result is a blank page !
Even if I place only the shortcode (without conditional) !
For info, I have replaced 'state-city' with the slug of the postype that is child of the "objet" that is displayed in this page (content template of objet) which is 'wishlist'
Concerning your last question, yes I want to check also that post author is same as loggedin user
Ok - great, Well - you do not need to replace post type name but post relationship slug.
Could you please share problem URL and access details so I can check whats going wrong there.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
You're right, I'm not using the latest version because this is on this site that I have made some modification on the Cred plugin in order to integrate the image rotation function.
Is there another way to define the relationship I need to place in the function?
First of all could you send me debug info so I can check your current site setup and after that I can able to guide you. I think you missed to shared debug information.
[wpv-conditional if="( '[child-post-exists]' eq '0' )"]
no child post available
[/wpv-conditional]
[wpv-conditional if="( '[child-post-exists]' ne '0' )"]
Yes - yes child post available
[/wpv-conditional]
Where:
- Register shortcode name child-post-exists at :
=> Tooset => Settings => Front-end Content => Third-party shortcode arguments
Could you please confirm it works or not. Also, you want to match the current post (which is a parent post you are displaying) author should be equal to loggedin user?
I think the best would be to modify the function "func_child_post_exists" in order to add the loggedin user condition.
That would allow to add this condition without changing anything to the content template.
Regards
Pat