WordPress.org

Ready to get started?Download WordPress

Forums

User Taxonomies
Terms not assigned to a user are displayed as ticked (8 posts)

  1. dashaluna
    Member
    Posted 1 year ago #

    Hello,

    I've added a taxonomy to Users with several terms on that taxonomy. I've assigned different multiple terms to different users.

    However, I've noticed that some users in the Admin screen would have terms displayed as ticked (assigned to them) even though they haven't been assigned to them!! I've checked the DB and the correct data is stored there, but on the admin additional terms are displayed as ticked!

    I've looked at the code and changed the following line:
    <input type="radio" name="<?php echo $key?>" id="<?php echo "{$key}-{$term->slug}"?>" value="<?php echo $term->slug?>" <?php checked(true, is_object_in_term($user->ID, $key, $term))?> />

    to

    <input type="radio" name="<?php echo $key?>" id="<?php echo "{$key}-{$term->slug}"?>" value="<?php echo $term->slug?>" <?php checked(true, is_object_in_term($user->ID, $key, $term->term_id))?> />

    I think that is_object_in_term() is behaving unexpectedly when passed a term object, rather than its ID. That seems to fix it.

    I hope that helps someone!

    Thanks for the plugin! Perhaps you will consider updating it with that bit of code, no worries if not, it might be just misbehaving a bit in my case :)
    Dasha

    http://wordpress.org/extend/plugins/user-taxonomies/

  2. wptobbe
    Member
    Posted 10 months ago #

    I'm having the same problem as you did, but your solution throws me this error:

    Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'my_show_extra_profile_fields' was given in /storage/content/25/146625/mace.jdesign-digital.se/public_html/wp-includes/plugin.php on line 406

    The error no longer shows when if I remove the function my_show_extra_profile_fields form my functions.php, but the taxonomy terms are still being checked when they shouldn't be.
    I should say that I have modified the tag to be output as checkboxes and not radio-buttons, so my tag looks like this:

    <input type="checkbox" name="<?php echo $key?>[]" id="<?php echo "{$key}-{$term->slug}"?>" value="<?php echo $term->slug?>" <?php checked(true, is_object_in_term($user->ID, $key, $term))?> />

    I changed the absolute last variable to $term->ID.
    My issue now is that if I check one term, they all get checked upon save. If I uncheck all of them and save, they stay unchecked. As long as one of them have been clicked then all of them become checked.

  3. dj maskell
    Member
    Posted 10 months ago #

    dashaluna Had the same problem and came to the same solution. This is an important one, I hope the developer includes this fix in a future version.

    Background info, when a term array is passed to is_object_in_term(), it apparently checks the database fields for both "term_id" AND "term_taxonomy_id" which are NOT the same thing. Specifying that you want to check a specific term_id instead of the full array solves the problem.

    wptobbe You mis-spelled the last variable. You wrote "$term->ID" when it should be "$term->term_id". That should fix your problem.

  4. dashaluna
    Member
    Posted 10 months ago #

    dj maskell great, glad it helped someone, I've spend hours catching this bug!
    Thank you for the explanation of the is_object_in_term() function, makes sense.

    wptobbe I hope you will make it work now.

  5. wptobbe
    Member
    Posted 10 months ago #

    Yes I got it working, changed the reference to $term->term_id and all seems to work perfectly now.
    Thank you for helping out!

  6. jordan314
    Member
    Posted 9 months ago #

    Thanks for this, I had the same problem

  7. derol
    Member
    Posted 8 months ago #

    I needed this fix too, so just for clarity for anyone else, heres the full code:

    <input type="checkbox" name="<?php echo $key?>[]" id="<?php echo "{$key}-{$term->slug}"?>" value="<?php echo $term->slug?>" <?php checked(true, is_object_in_term($user->ID, $key, $term->term_id))?> />

  8. anterys
    Member
    Posted 5 months ago #

    Came here to post the same solution. Glad it's already there. For me the results were mostly right which threw me for a look. @djmaskell, that makes some sense as to why it was mostly working.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic