I try to fetch all posts from a custom post type in Wordpress and include the advanced custom fields (ACF) in the results as well, in order to generate a JSON file with the data.
$query = new WP_Query(array(
'post_type' => 'resources',
'post_status' => 'publish',
'posts_per_page' => -1,
));
echo "var json=". json_encode($query->get_posts());
With a simple WP_Query
, ACF data are not included and I have to iterate in the results and fetch all ACF manually one by one. Is there any way to include them in the original WP_Query
results?