Skip Navigation

[Resolved] Conditional output based on child post

This support ticket is created 3 years, 9 months 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 1 reply, has 1 voice.

Last updated by troyC 3 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#1929361

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

#1929901

My issue is resolved now. Thank you!