Hi there,
I am building a custom plugin by using AFC PRO and have used generic boilerplate of WordPress plugin. Anyhow, I am using version 5.4.4 with latest wordpress version.
Problem
1) I have created some field group in Custom fields that associated with Custom post type. In repeater, I used two additional text field that I need to call in option page that is build with Redux Framework. Because I need to dynamically populate some option fields based on custom posts values.
2) I used that code
$args = array('post_type' => 'material');
$materials = get_posts($args);
foreach ( $materials as $post ) :
setup_postdata( $post );
echo $post->ID . '---';
echo the_title() . '<br>';
echo get_field("sub_material_name") . "<br>";
$rows = get_field('sub_material_name');
var_dump($rows);
if($rows)
{
echo '<ul>';
foreach($rows as $row)
{
echo '<li>sub_material_name = ' . $row['sub_material_name '] . ', sub_material_price = ' . $row['sub_material_price '] .', etc</li>';
}
echo '</ul>';
}
endforeach;
wp_reset_postdata();
3) $rows = get_field(‘sub_material_name’) line only returns the number of subfield like 2 but not array and foreach return the waring that its not an array, means I used has_rows and even has_sub_fields both return Null.
But its only works in theme. Is there I missed something?
Hi @raheem
This issue mostly causes by a custom query set somewhere in your plugin or theme. This custom query usually tries to change something but doesn’t check if it’s querying ACF’s data or not. The result is ACF fails to get the data needed to parse the returned result.
Could you please try to reproduce the issue on one of the WordPress’ stock themes (like Twenty Sixteen) with other plugins deactivated? If it disappears, then you can activate the theme and plugins one by one to see which one causes the issue.
I hope this makes sense. Thanks!