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.

I'm modifying the plugin Wordpress Frontend User for my custom post type(s). What I need to edit is the custom taxonomy terms. In order to do this, I need to list my terms as labels and have checkboxes associated with the labels (in the end associated with the taxonomy when I send a post update).

What I have now is as follows:

$jobsTerms = get_terms('jobtype',array( 'taxonomy' => 'jobtype' )); 
foreach($jobsTerms as $term){
    echo "<label for='term-" . $term->slug . "'>" . $term->name . "</label>";
    echo "<input type='checkbox' name='term" . $term->slug . "' value='" . $term->name . "' />
}

But other than that, I'm lost as to how to check to see if that post has a term selected (if so add checked=checked to the input).

I'm also lost as to how to update this taxonomy when I click submit (which fires a couple custom update_post_meta calls and a wp_update_post call.

Any help?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Try this:

$jobsTerms = get_terms('jobtype',array( 'taxonomy' => 'jobtype' )); 
foreach($jobsTerms as $term){
    $checked = (has_term($term->slug, 'jobtype', $post->ID)) ? 'checked="checked"' : '';
    echo "<label for='term-" . $term->slug . "'>" . $term->name . "</label>";
    echo "<input type='checkbox' name='term" . $term->slug . "' value='" . $term->name . "' $checked />";
}

Replace $post_id with whatever you need to get the ID, I'm not sure where exactly this code goes. It may be $post->ID.

share|improve this answer
    
After changing $post_id to $post->ID (thanks for the suggestion, I didn't notice it was $post_id until I read the whole comment), it now calls them correctly and displays checked for the correct postings. The only thing I'm left with now is finding out how to save changes to them (post_meta?) Anyways, +1 for your answer, I'll be looking in the Gravity Forms + Custom Post Type plugin to see how it's handled. Thanks again! –  Josh Allen Aug 26 '11 at 13:09
    
Also, because I can't edit, you should change in the <input> the name='term" to name='term-" to match the consistency for the label. –  Josh Allen Aug 26 '11 at 13:13

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.