Skip Navigation

[Résolu] Child post counts

This support ticket is created Il y a 3 années et 1 mois. 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

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

Last updated by hansooH Il y a 3 années et 1 mois.

Assisted by: 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

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.