Browser: Chrome 110 OS: macOS / Windows / Linux / etc. URL: Link to a page that illustrates this issue Video: Short screen recording that illustrates this issue (free tool: jam.dev)
[Please describe this bug in as much detail as possible so we can replicate & debug this bug]
Hi guys
Has anybody got a simple solution for this? I’ve got a ACF repeater with content in, and a true/false field, I just very simply want to use that field to hide/show the entries.
I’ve tried using conditions inside a block in the ACF repeater query, but it won’t change the outside query count so it still returns a blank div? It seems that Bricks gives no meta option either when choosing ACF repeater in the Query.
I can use CSS, but I really want to target the main query properly to check for a meta value of 1 before the items are returned.
Aware @aslotta helped before with this, but I’m unsure if I’m overcomplicating it or not?
Sometimes you don’t want to delete the content from the repeater, in particular clients don’t always in case the content is reinstated. Sure, I could make them into posts, but in this use case I had repeaters and just wanted to run the query through a meta key filter
For reference and to help others, I ended up using this to get this to work based on André’s help and code before:
You need to change the page ID’s the loops are on you want to filter, the first line needs to be the repeater name (results limit doesn’t seem to do much) and make sure to change the true/false or other ACF subfield you want to base the return of the row from
@aslotta - any idea what the results filter doesn’t work?
add_filter('acf/format_value/name=name_of_ACF_repeater', function ($value, $post_id, $field) {
// Get the current page/post ID
$current_post_id = get_the_ID();
// Define the specific page/post IDs to target
$target_post_ids = [2, 3]; // Replace with your actual page or post IDs
// Check if the current page/post ID matches one of the target post IDs
if (!in_array((int)$current_post_id, $target_post_ids, true)) {
return $value; // Return the unfiltered value if the condition is not met
}
// If the ID matches, proceed with your filter logic
if (is_array($value)) {
// Filter the repeater rows where 'subfield_acf' is true (checked)
$filtered = array_filter($value, function ($row) {
return !empty($row['subfield_acf']); // Include rows where 'subfield_acf' is true
});
// Randomize the filtered results
shuffle($filtered);
// Limit the number of results to 3
$limited = array_slice($filtered, 0, 3);
} else {
$limited = $value; // Return unfiltered if not an array
}
return $limited; // Return the limited and randomized repeater data
}, 10, 3);