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;
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.