Hi,
I have a CPT called "class" which is a parent of CPT "challenge".
I would like to define a conditional output based on the following statement :
- a child "challenge" post exist
- it has the same author than the current logged in user
I have tried using the code given an other ticket:
https://toolset.com/forums/topic/conditional-output-based-on-child-post/
[code]
[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]
[/code]
added to functions.hp
[code]
function func_child_post_exists( $atts ){
global $post;
$args = array(
'post_type' => 'class-challenge', // change your child post slug IF needed
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => '_wpcf_belongs_objet_id',
'value' => $post->ID,
)
)
);
$chids = get_posts( $args );
return count($chids);
}
add_shortcode( 'child-post-exists', 'func_child_post_exists' );
[/code]
I have registered the shortcode ' child-post-exists'.
Can you help met to understand how to get this to work?
Its now to showing the results i expect
My issue is resolved now. Thank you!