If running a normal Post Loop Query, to return the posts as cards, how would I then be able to check if ANY content was present in any of the fields in a given ACF Repeater, and show a button if so, but another button if not?
Could be over-complicating it, but just curious as nothing on here yet has seemed to handle that.
You would make a condition with {query_results_count:queryid} that checks if more than 0 items were found.
Query fields
{query_results_count} – Use inside or outside a query loop to return the query results count (@since 1.9.1). When used outside a loop you have to pass the query loop ID as a filter to this tag like this: {query_results_count:quer34} . “quer34” in this example is the query loop ID, which you can retrieve by copying the element ID of the query element into your clipboard. Make sure to remove the “#brxe-” prefix. You only want to use the last six-character ID.
@Patric - So that will check if there’s 1 or more, in the loop (i.e on a given post/CPT you want to check if any of the repeater fields are filled, and if so, it’s true). Or would that be >= ?
Related:
If you are looking to check the presence of rows in a repeater or flexible content related query, I use this:
WPCodebox2:
<?php
function check_acf_flexible_content($field_name, $post_id = false) {
// If a post ID is not provided, use the current post ID
if (!$post_id) {
$post_id = get_the_ID();
}
// Check if the specified field has any rows
if (have_rows($field_name, $post_id)) {
return true;
}
return false;
}
and in the builder conditions: {echo:check_acf_flexible_content(insert_name_of_flexible_content_or_repeater_acf_field)}
Just for the sake of somebody else reading this, in your example there, as the Toggle icon is outside the loop it would then require the ID for that element in the condition too, right?