Home › Forums › Front-end Issues › Set post object field using php › Reply To: Set post object field using php
Thank you very much for your reply James. Just a question: using the update field is not the right method, isn’t it?
I was able to pass post ID in the new_review.php:
<?php $id_contributo = $_POST['id_contributo']; ?>
//get proposal idfrom previous page
<h3>Proposal reviewed: <?php echo $id_contributo; ?></h3>//display original proposal title
<?php update_field('proposal_reviewed', $id_contributo);?> //update post object field content
<?php echo get_field('id_contributo');?> //echo the value
//form used to create the new review
<?php acf_form(array(
'post_id' => 'new_review',
'submit_value' => 'Create',
));?>
and in function.php:
function my_pre_save_review( $post_id ) {
// bail early if not a new review
if( $post_id != 'new_review' ) {
return $post_id;
}
// Create a new post
$review = array(
'post_status' => 'publish',
'post_type' => 'reviews',
);
$post_id = wp_insert_post( $review );
// return the new ID
return $post_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_review' );
Echoing the value in the front-end works, but if I open the review from admin panel the object field is not updated.
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.