Advanced Custom Field not present in post object

I noticed that while looping over a post, the_field(‘item_title) is returning empty.

I’m debugging the post object, and I’m not seeing any advanced custom fields.
Correct me if i’m wrong but they’re supposed to be under a certain meta key in the post object(?).

custom post type registry:

function art_init()
{
$arts_labels = array(
‘name’ => ‘Arts’,
‘singular_name’ => ‘Art’,
‘menu_name’ => ‘Arts’
);

$args = array(
‘labels’ => $arts_labels,
‘public’ => true,
‘show_ui’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘rewrite’ => array(‘slug’ => ‘art’),
‘query_var’ => true,
‘menu_icon’ => ‘dashicons-welcome-widgets-menus’,
‘supports’ => array(
‘title’,
‘editor’,
‘excerpt’,
‘trackbacks’,
‘custom-fields’,
‘comments’,
‘revisions’,
‘thumbnail’,
‘author’,
‘page-attributes’,)
);
register_post_type(‘art’, $args);
}

add_action(‘init’, ‘art_init’);

post debugging:

$posts = get_posts([
‘numberposts’ => -1,
‘post_type’ => ‘art’,
]);
if ($posts) {
foreach ($posts as $postKey => $postValue) {
var_dump($postValue->meta_key);
$postAcfFields = get_fields($postValue);
//var_dump(‘$postAcfFields: ‘.count($postAcfFields));
if ($postAcfFields[‘item_images’]) {
$postObjWithImages[$postValue->ID] = $postAcfFields;
}
}
}

Debug returns:

object(WP_Post)[1600]
public ‘ID’ => int 1840
public ‘post_author’ => string ‘1’ (length=1)
public ‘post_date’ => string ‘2018-10-13 10:53:45’ (length=19)
public ‘post_date_gmt’ => string ‘2018-10-13 10:53:45’ (length=19)
public ‘post_content’ => string ” (length=0)
public ‘post_title’ => string ‘this is a contact’ (length=17)
public ‘post_excerpt’ => string ” (length=0)
public ‘post_status’ => string ‘publish’ (length=7)
public ‘comment_status’ => string ‘open’ (length=4)
public ‘ping_status’ => string ‘open’ (length=4)
public ‘post_password’ => string ” (length=0)
public ‘post_name’ => string ‘this-is-a-contact’ (length=17)
public ‘to_ping’ => string ” (length=0)
public ‘pinged’ => string ” (length=0)
public ‘post_modified’ => string ‘2018-10-13 13:47:17’ (length=19)
public ‘post_modified_gmt’ => string ‘2018-10-13 13:47:17’ (length=19)
public ‘post_content_filtered’ => string ” (length=0)
public ‘post_parent’ => int 0
public ‘guid’ => string ‘http://website.com/?post_type=art&p=1840’ (length=61)
public ‘menu_order’ => int 0
public ‘post_type’ => string ‘art’ (length=3)
public ‘post_mime_type’ => string ” (length=0)
public ‘comment_count’ => string ‘0’ (length=1)
public ‘filter’ => string ‘raw’ (length=3)

get_fields() in the post object loop shows a separate array of all ACF fields with no connection to post attributes (link, title, etc), so as you can see there, I created an assoc array to help with that, but that makes all my queries unoptemized, sluggish and very hard to combine with HTML (bootstrap slider with multi inner-items based on post).
I am interested in using get_field(), each ‘post_type’ => ‘art’ has many images.

Read more here:: Advanced Custom Field not present in post object

Leave a Reply

Your email address will not be published. Required fields are marked *