Skip Navigation

[Résolu] Return The Number of Child Posts in a Parent View – Follow Up

This support ticket is created Il y a 3 années et 2 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
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 réponses, has 2 voix.

Last updated by Ed Il y a 3 années et 2 mois.

Assisted by: Christian Cox.

Auteur
Publications
#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!

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