I'm displaying a list of custom taxonomies from a custom post type on a frontend page which shows any items that the user has previously selected as checked.

I have got it displaying correctly, but I can't manage to work out how to save any new / changed selections.

This is the code I'm using to display the terms :

$args = array(
    'descendants_and_self'  => 0,
    'selected_cats'         => false,
    'popular_cats'          => false,
    'walker'                => null,
    'taxonomy'              => 'genres',
    'checked_ontop'         => false

wp_terms_checklist( $my_postid, $args ); 

Which outputs like this on the page :

<li id='genres-28'><label class="selectit"><input value="28" type="checkbox" name="tax_input[genres][]" id="in-genres-28" checked='checked' /> 2 Step</label></li>

<li id='genres-14'><label class="selectit"><input value="14" type="checkbox" name="tax_input[genres][]" id="in-genres-14" checked='checked' /> Afro House</label></li>

<li id='genres-7'><label class="selectit"><input value="7" type="checkbox" name="tax_input[genres][]" id="in-genres-7" checked='checked' /> Bassline</label></li>


I'm setting up the post data like this :

$post_to_edit = array(
    'ID'           => $my_postid,
    'post_content' => $_POST['editor'],
    'tax_input'    =>  array( 'genres' => array($_POST['tax_input[genres]']) )

$pid = wp_update_post($post_to_edit);

Then I'm trying to the update the terms like this :

wp_set_post_terms($pid,(array)$_POST['tax_input[genres]'],'genres', true);

And I've also tried :


But neither are working?

I'm guessing that I'm not selecting the right name attribute but I've tried everything I can think of for the past 24hrs and just can't get the terms to save to the database.

Does anybody know how I can save/update the values output from wp_terms_checklist?

  • Update : I'm definitely not selecting the right name tag as when I try to print the array I get - Array ( [0] => ) – Grant Aug 22 '15 at 13:28

$_POST['tax_input[genres]'] should be $_POST['tax_input']['genres']

| improve this answer | |
  • You sir, are a legend! I have been banging my head against the computer screen for hours upon hours trying everything I could think of. Thank yo so much! – Grant Aug 22 '15 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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