Support

Account

Home Forums General Issues Get number of posts in a given ACF category

Solving

Get number of posts in a given ACF category

  • Hi!
    I want to get the number of posts in a given ACF category.
    Until now, I was using the following function to create a shortcode for WordPress native categories:

    
    // Add Shortcode to show posts count inside a category
    function category_post_count( $atts ) {
    
        $atts = shortcode_atts( array(
            'category' => null
        ), $atts );
    
        // get the category by slug.
        $term = get_term_by( 'slug', $atts['category'], 'category');
    
        return ( isset( $term->count ) ) ? $term->count : 0;
    }
    add_shortcode( 'category_post_count', 'category_post_count' );
    

    Is there anything similar that could be done with ACF?

  • Is there anyone with a solution on this?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.