Hi.
Im starting now with ACF and im doing a very simple custom field. What I want is use a custom field to choose from galleries inside my WP.
From the examples, i did this:
function my_acf_load_field($field) {
$field['choices'] = array();
# Buscar galerias no banco
$result = new WP_Query(array('post_type' => 'gallery'));
foreach($result->posts as $gallery) {
$field["choices"][$gallery->ID] = $gallery->post_title;
}
return $field;
}
add_filter('acf/load_field/name=galeria', 'my_acf_load_field');
It works well, I can read the name of the gallery and the id as a value.
Then, in the website, when i want to get the value, I do this to get the value:
$my_gallery = get_field('galeria');
But, right above this line I see this message:
Notice: Trying to get property of non-object in /Users/<project_path>/www/wp-content/plugins/advanced-custom-fields/acf.php on line 215
Does anyone knows what am I doing wrong?
Thank you.
Hi, i´m having the same error, my code is very simple, the content of the custom field shows correctly but, this message error is displayed:
Notice: Trying to get property of non-object in {path}\wordpress\wp-content\plugins\advanced-custom-fields\acf.php on line 215
any help?
Code:
`<?php if (have_posts()) : while (have_posts()) : the_post();?>
<?php the_content(); ?>
<?php
echo get_field( “Destacado” );
?>
<?php endwhile; endif; ?>