Home › Forums › Bug Reports › ACF returning ID instead of an array and count of repeater instead of an array › Reply To: ACF returning ID instead of an array and count of repeater instead of an array
Here’s my situation. What do we have:
Custom post type “items” which has the following field group “Item” with the one image type field. It should returns to array.
Also the current user has a group of fields “User dictionaries”.
My code is:
$args = array(
'posts_per_page' => '-1',
'post_type' => 'items',
);
$myitems = new WP_Query( $args );
if ( $myitems->have_posts() ) :
while ( $myitems->have_posts() ) :
$myitems->the_post();
$image = ( get_field( 'image' ) ) ? get_field( 'image' ) : false;
$dic = get_field( 'dictionaries', 'user_' . get_current_user_id() );
//code...
endwhile;
endif;
wp_reset_postdata();
In this case get_field for $image returns an array as it should be and get_field for $dic returns an array of the repeater field dictionaries of current user as it should be.
But my goal is to get on the archive page a certain kind of items.
For this I use the hook “posts_where” for modified request.
My code:
global $wpdb;
add_filter( 'posts_where' , 'my_where' );
function my_where( $where ){
$where .= " AND wp_posts.post_title LIKE 'b%'";
return $where;
}
All items are returned correctly. But get_field for $image now returns the ID of image and get_field for $dic now returns the digital value of the number of fields of the repeater.
Json file of the field groups is attached.
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.