Home › Forums › General Issues › ACFs update_field() and displaying in custom cloumns
I cannot use ACF update_field() to insert a new post on install. update_post_meta works fine. I can insert images and even see them in my custom columns. I cannot get anything to work using update_field();
How do I?
a. Get update_field() to work
b. Display my updated fields in my custom columns
Any help would be much appreciated.
This may help. http://support.advancedcustomfields.com/discussion/comment/20041#Comment_20041
my plugin`function newplugin_install() {
$pid = array(
//'ID' => 22,
'post_title' => 'One Once Un Single',
'post_excerpt' => '(first). Lorem ipsum dolor set elit…',
'post_content' => '(FIRST). Lorem ipsum dolor sit amet, consectetur adipisicing elit. Unde, id, repellat, ut hic repellendus corrupti delectus molestiae cumque at esse neque maxime molestias iure explicabo expedita quisquam reprehenderit in tempora illo fuga.',
'post_status' => 'publish',
'post_type' => 'exhibitor'
// INSERT Featured Image
);
// Save the Exhibitor
$insert = wp_insert_post($pid);
// a.
// update_post_meta($insert, 'stand', 1 );
// update_post_meta($insert, 'url', 'www.google.co.uk' );
// update_post_meta($insert, … );
// update_post_meta($insert, 'tel', '(0141) 123 4567' );
// update_post_meta($insert, '_thumbnail_id', 194 );
// update_post_meta($insert, 'logo', 173 );
// ACFs
update_field('field_1', 11, $insert );
update_field('field_3', 'www.google.co.uk', $insert );
update_field('field_4', '[email protected]', $insert );
update_field('field_5', '(0141) 123 4567', $insert );
// INSERT ACF Image Type ???
//update_field($insert, 'logo', 173 );
}`
My columns`case 'stand' :
/* Get the post meta. */
$stand = get_post_meta( $post_id, 'stand', true );
//$stand = get_field('stand');
/* If no Stand Number is found, output a default message. */
if ( empty( $stand ) ) {
echo __( $stand );
} else {
/* If there is a Stand Number, prepend # to the text string. */
$standno = sprintf('%02d', $stand);
//$standno = “hey”;
echo “#” .__( $stand );
}
break;`
Hi,
It is possible that the update_field function does not work during the ‘newplugin_install’ action.
Have you tried using update_field in another action such as admin_head to test that it works?
If you can test that and confirm that the issue is due to the time when it is run, I can have a look at finding a fix
Correct.
I managed do get update_field to work in admin_head action. However, this adds multiple posts for every refresh. Not what I want.
Should I report this as a bug?
Hi,
I’ll add this to the to-do list and find a fix.
Thanks for the bug report.
The topic ‘ACFs update_field() and displaying in custom cloumns’ is closed to new replies.
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.