The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

populate a custom field on publish or update

  • # July 6, 2014 at 6:34 pm

    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)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed