Home › Forums › Backend Issues (wp-admin) › Invalid Array from Relationship Field Type › Reply To: Invalid Array from Relationship Field Type
// use get_queried_object because you might not be showing
// something that returns an value for get_queried_object_id()
$queried_object = get_queried_object();
// initialize $persons in case nothing is returnd for field
$persons = false;
// test queried object to see if it's a post
if (is_a($queried_object, 'WP_POST')) {
$persons = get_field('persons', $queried_object->ID);
}
// test $persons to make sure something was returned
if (!empty($persons)) {
foreach ($persons as $post) {
setup_postdata($post);
?><meta name="author" content="<?php the_title() ?>" /><?php
}
wp_reset_postdata();
}
// if nothing was returned for $persons show a default
// if this is a single post
if (!$persons && is_single()) {
?><meta name="author" content="<?php echo get_the_author_meta('display_name', $post->post_author); ?>"><?php
}
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.