The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End populate a custom field on publish or update

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
  • #174849

    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[] = strip_tags(get_field('bookstore',$post)); 
        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.


    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

Viewing 1 post (of 1 total)
  • The forum ‘Back End’ is closed to new topics and replies.