Skip Navigation

[Résolu] Child post counts

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.

This topic contains 6 réponses, has 2 voix.

Last updated by hansooH Il y a 9 mois et 2 semaines.

Assigned support staff: Minesh.

Auteur
Publications
#1953205
error sample 2.jpg

I am trying to:
I have used "child post counts function" that you posted here.
https://toolset.com/forums/topic/count-child-post-2/

Recently, I updated toolset latest version and I found this function is not working.

I uploaded a image, the fifth column values has all "0"
page link is
hidden link

and here is my code on snippet

add_shortcode('wpv_child_post_count', 'wpv_child_post_count_fun');
function wpv_child_post_count_fun($atts) {

extract( shortcode_atts( array(
'parent_post_id' => '',
'child_post_type' => 'member', // child cpt slug
), $atts ) );

$child_posts = array( 'post_type' => $child_post_type, 'meta_query' => array(array('key' => '_wpcf_ministry-cert_id', 'value' => $parent_post_id))); // parent cpt slug
$child_posts = get_posts( $child_posts );
return count( $child_posts );
}

Link to a page where the issue can be seen:

I expected to see:
I need figure it out this problem

Instead, I got:

#1953309

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share one post link where you added the related member posts?

#1953321

Here is a member post page. Thanks

hidden link

#1953345

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now:
- hidden link

See the "SNU Huddle" and it shows the 1.

I've adjusted the child post count shortcode as given under:

add_shortcode('wpv_child_post_count', 'wpv_child_post_count_fun');
function wpv_child_post_count_fun($atts) {
      
    extract( shortcode_atts( array(
        'parent_post_id' => '',
        'relationship' => '', // child cpt slug
    ), $atts ) );
  
  $related_posts = toolset_get_related_posts(
                                    $parent_post_id,
                                    $relationship,
                                     'parent',
                                     9999,
                                      0,
                                      array(),
                                     'post_object',
                                     'child'
                                     );
 
return count($related_posts);  
    
  /*
    $child_posts = array( 'post_type' => $child_post_type, 'meta_query' => array(array('key' => '_wpcf_ministry-cert_id', 'value' => $parent_post_id))); // parent cpt slug
    $child_posts = get_posts( $child_posts );
    return count( $child_posts );
   */
}

And called the shortcode as:

[wpv_child_post_count parent_post_id='[wpv-post-id]' relationship='huddle-member']
#1953369

I'm sorry I didn't have enough explanation.
The parent (ministry-cert) has child (multiple members), and the page described above should show the number(count) of posts of the children that all parents have. 🙂

#1953389

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

The shortcode is returning the count only.

Can you please share an example with explanation with what post you want to include as count?

Lets the the following post: hidden link

The above post having only one related post, so could displays 1.

#1953413

My issue is resolved now. Thank you!
Sorry Again. Your work is just perfect. The first page count number is all "0" which is correct, so I assume that it was not working. but last page has correct number of count. Perfect and so good. 🙂
Thank you very much, Minesh