Skip Navigation

[Resolved] Return The Number of Child Posts in a Parent View – Follow Up

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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by Ed 3 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1926915

Ed

Referencing the following ticket, is there any reason this solution would stop counting at 10? I only ask because it stops counting at 10.

https://toolset.com/forums/topic/return-the-number-of-child-posts-in-a-parent-view/

I'll provide admin access when requested.

#1926997

Hi, I recommend changing that custom code to remove the 10-post per page pagination limit. Replace numberposts with posts_per_page, like so:

add_shortcode('review-count', 'review_count_func');
function review_count_func()
{
 
$child_args = array(
    'post_type' => 'reviews',
    'posts_per_page' => -1,
'post_status'=>'publish',
    'order' => 'ASC',
    'toolset_relationships' => array(
        'role' => 'child',
        'related_to' => get_the_ID(),
        'relationship' => 'my-relationship-slug'
    )
);
  
$query = new WP_Query( $child_args );
$child_posts = $query->posts;
return count($child_posts);
}

Replace reviews with the slug of the reviews post type, and replace my-relationship-slug with the slug of the post relationship. Does this fix the problem? If not, I may need to take a closer look.

#1927009

Ed

That'll do it! Thank you!