Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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

Do a var_dump($_POST) if in doubt.

share|improve this answer
    
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 Dec 4 '12 at 19:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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