Home Forums ACF PRO Post count for each meta value


Post count for each meta value

  • I need to count the number of posts for a range of custom meta and serialize the output in PHP. I can’t get the count numbering to work. Any suggestions how to get this to work (see [????])…

    // Preparing a WP_query
    $the_query = new WP_Query(
    'post_type' => 'post',
    'post_count' => -1
    $return_array = array(); // Initializing the array that will be used for the table
    while( $the_query->have_posts() ){
    // Fetch the post
    //Idee status
    $field = get_field_object('field_5b4f48e937d4f'); // array of choices
    $value = get_field('field_5b4f48e937d4f');
    $label = $field['choices'][ $value ];
    // Filling in the new array entry
    $return_array[] = array(
    'Status' => $label,
    'Count' => [????] // What should I put here to count # posts for each $label
    // Now the array is prepared, we just need to serialize and output it
    echo serialize( $return_array );
Viewing 1 post (of 1 total)

The topic ‘Post count for each meta value’ is closed to new replies.