Home › Forums › Add-ons › Repeater Field › Repeater field returns count of values
I have a repeater field called “images” with a sub field called “image”. In a post, I’ve added 4 images to the repeater field.
When trying to display this repeater field, I’m doing var_dump(get_field("images"))
which is returning string(1) "4"
which is just a count of the number of values for the repeater. I’ve tried the examples on the website documentation and if using the loop method, the loop never executes.
I’ve tried different field types in the repeater field such as text with the same result.
I’m using the latest WordPress version but have also tested with version 4.9.10 with the same result.
There is a pre_get_posts query somewhere that is interfering with ACF’s query to get the repeater field. This is the case 99% of the time when this happens.
Start by deactivating other plugins to see if one of them is the culprit. If not then it’s possible a pre_get_posts filter in your theme.
John,
You are a life saver… I’ve identified it down to my custom theme where I have a pre_get_posts filter. My filter was in place so that I could display custom post types on a category page.
Strange behavior though… When ACF is retrieving the field meta data it is being identified as a category is_category() == true
. What I noticed is that the meta query doesn’t have a category name so I just added a check for that and everything is happy now.
Any idea why the custom field query is being identified as a category?
My original filter ($this->customPostTypes has my custom post type names):
if (is_category()) {
$postType = get_query_var("post_type");
if (!$postType) {
$postType = [
"nav_menu_item",
"post",
];
foreach ($this->customPostTypes as $customPostTypes) {
$postType[] = $customPostTypes["type"];
}
}
$query->set("post_type", $postType);
}
return $query;
Updated filter:
if (is_category() && isset($query->query["category_name"])) {
$postType = get_query_var("post_type");
if (!$postType) {
$postType = [
"nav_menu_item",
"post",
];
foreach ($this->customPostTypes as $customPostTypes) {
$postType[] = $customPostTypes["type"];
}
}
$query->set("post_type", $postType);
}
return $query;
is_category()
is looking at the main wp query, not the current query.
isset($query->query["category_name"])
is likely always true
isset($query->query["category_name"])
is false for the ACF queries. I just var dumped the $query for everything that matched is_category()
and was able to isolate the two.
The topic ‘Repeater field returns count of values’ is closed to new replies.
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.