This is kinda complicated as a custom field could be attached to something else than a post type. It can be attached to a specific page, a taxonomy or a lot of other things. In fact it is attached to all the posts which correspond to the type of object(s) you attach the custom field.
That’s why (I think) the get_field_object() requires at least one $post_id to be found.
When displaying a post editor, or taxonomy editor or any form that ACF let’s you add a field group to ACF determines this by looking at the location rules for that field group and comparing them to the current “location”. When the post is saved in the admin the fields are saved to the object being saved, there isn’t any reason to check the location, acf just saves any ACF fields that are submitted using the current WP object ID.
When getting values ACF uses the global “$post->ID” to get values and this is why you must supply a post ID for anything other than the post in “The Loop”
In order to do what you want you would need to do a WP query for a post in that post type where the field “Exists” and then use the post ID returned from this in combination with the field name to get the field object.
Alternately, this can be done more easily by using the field key get_field_object('field_0123456789abc');
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Like w/ ACF you could have a dozen different themes that use the same fields but make it look different. With a page builder you have data storage AND visual lock-in and something like rebranding means you can’t just change a few theme colors, you have to restart from scratch.