i am using acf to create the custom fields.
i trying to populate a custom field bookstore in the books posttype based on the selected booklist
function update_bookstore_field( $post_id ) {
if( $_POST['post_type'] == 'books' ){
$booklist = get_field('booklist');
foreach ($booklist as $post) : setup_postdata($post);
if (!empty($post)){
$bookstore=array();
$bookstore[] = strip_tags(get_field('bookstore',$post));
}
endforeach;
wp_reset_postdata();
update_post_meta( $post_id, 'bookstore', $bookstore[0] );
}
add_action( 'save_post', 'update_bookstore_field' );
where booklist is a posttype connected as a postobject to books, based on the selection of the book in the booklist the custom field bookstore in posttype = books is filled with corresponding bookstore of booklist posttype.
e.g
booklist bookstore wiz of oz amazon wiz of oz 1 flipkart wiz of oz 2 barnes&noble
so if the in select field ok books posttype “wiz of oz 1” is selected in the booklist the the bookstore in books shud be populated with flipkart automatically on clicking publish or update…thts not happening