Quantcast
Channel: Toolset » All Posts
Viewing all articles
Browse latest Browse all 20145

Test for child posts

$
0
0

Hi,

Have not been able to implement a wpv-if statement that tests for child posts, despite using what seems to have worked for some people. I am trying to implement a slider on 'post' types, but only if the post has an associated child CPT named 'slide'. Here's the code I was trying:

function has_child_func( $atts ) {
    extract( shortcode_atts( array(
        'parent_id' => '',
    ), $atts ) );
  
    $childargs = array(
        'post_type' => 'slide',
        'meta_query' => array(array('key' => '_wpcf_belongs_post_id', 'value' => $parent_id))
);
$child_posts = get_posts($childargs);
$i=0;
foreach ($child_posts as $child_post) {
  $i++;
}
return $i;
}
add_shortcode( 'has_child', 'has_child_func' );

And my shortcode

[wpv-if evaluate="[has_child parent_id = [wpv-post-id]] != 0"]SLIDER SHORTCODE HERE[/wpv-if]

What am I doing wrong?!? Any help would be much appreciated.


Viewing all articles
Browse latest Browse all 20145

Trending Articles