0

In my functions.php i'm trying to check if the user has selected a value in a custom field drop down and then set that value as the term of the post when it's published. I'm using the following function but it doesn't seem to work. Although if i select a term from the custom taxonomy check list and publish the post the term doesn't get saved. So i guess i'm close? No?

function artist_term_save( $post_ID ){

    // Bail if we're doing an auto save
    if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;

    //check if they selected your state term
    $artist = isset($_POST['magicfields[shop_artist][1][1]']) ? $_POST['magicfields[shop_artist][1][1]'] : ''; //make sure of what the input name is here...

    //insert post meta
    wp_set_object_terms($post_ID, $artist, 'byartist');
}

Note: magicfields[shop_artist][1][1] is the name of the select drop down in the HTML.

1 Answer 1

0

Access your post data as a real array: $_POST['magicfields']['shop_artist'][1][1].

Do a var_dump($_POST) if in doubt.

1
  • Many thanks Geert it almost worked. While it sets the term it appears with a number so i guess the output is the ID of the selected item.
    – drivebass
    Commented Dec 4, 2012 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.