Skip Navigation

[Gelöst] Child post counts

This support ticket is created vor 3 Jahren, 9 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 6 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von hansooH vor 3 Jahren, 9 Monaten.

Assistiert von: Minesh.

Author
Artikel
#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
versteckter 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

Sprachen: Englisch (English )

Zeitzone: 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

versteckter Link

#1953345

Minesh
Supporter

Sprachen: Englisch (English )

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

Can you please check now:
- versteckter 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

Sprachen: Englisch (English )

Zeitzone: 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: versteckter 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