Support

Account

Home Forums Add-ons Flexible Content Field Count flexible content rows of a particular row layout Reply To: Count flexible content rows of a particular row layout

  • The postmeta value stored for a flexible content field is an array where each element of the array is the layout of that row. I would do something like this.

    
    // get the post meta value without using ACF
    $rows = get_post_meta($post_id, 'flexible_content_field', true);
    // initialize layout counts in case there is nothing in the meta
    $layout_counts = array();
    if (is_array($rows)) {
      // have php count the values of the array
      $layout_counts = array_count_values($rows);
    }
    // initialize count at 0
    $count = 0;
    // see if any count for a layout
    if (isset($layout_counts['layout_1'])) {
      $count = $layout_counts['layout_1'];
    }
    echo $count;