WordPress.org

Ready to get started?Download WordPress

Forums

Radio Buttons for Taxonomies
[resolved] Doesn't work with Advanced Custom Fields (17 posts)

  1. Pietro Gregorini
    Member
    Posted 1 year ago #

    Hi there,
    I'm experiencing a problem with your plugin in conjunction with ACF.
    I want a taxonomy radio button to activate its own custom fields dinamically with Ajax.
    I saw that with ACF and classic taxonomy checkboxes it works.
    When I activate your plugin, suddenly it doesn't work anymore.
    I guess it's related to the taxonomy panel or object IDs which are renamed with your plugin.
    Is not possibile to change back taxonomy and categories IDs with the original one and make it work?
    I guess doing this would prevent plugin to experience several incompatibilities with other one.

    Let me know! Thank you!

    Pietro

    http://wordpress.org/extend/plugins/radio-buttons-for-taxonomies/

  2. Pietro Gregorini
    Member
    Posted 1 year ago #

    Kathy, any news about this?
    Please, it's quite urgent.

    Thank you very much,
    Pietro

  3. helgatheviking
    Member
    Plugin Author

    Posted 1 year ago #

    When I activate your plugin, suddenly it doesn't work anymore.

    Suddenly what doesn't work any more? What part specifically? Unfortunately there are a gazillion plugins and I cannot guarantee that mine will work with every other plugin. But if you describe exactly what you are doing and what is happening, I might be able to recreate the problem to investigate.

    Sorry for the delay, I thought I was subscribed to this forum, but was not. I should be now.

  4. Pietro Gregorini
    Member
    Posted 1 year ago #

    Hi Kathy,
    I'll try to explain as better as I can: I made some custom meta boxes and fields with ACF. Some of these are conditional: they are shown only when a specific category or taxonomy has been selected. So, when I check a category the related meta boxes appears. I guess this is done in ACF with some JQuery/AJAX script trick.

    When I activate your plugin, the categories became radio buttons (that is what I want) but selecting one of these doesn't activate the related meta boxes anymore on-the-fly.

    If you save the post with a radio button selected and then try to edit it, the related meta boxes are there, but it was helpful for me to have them on-the-fly just selecting the related category (you know, I work with many other users, so I need to have everything under control, since they have to strictly select just one category or taxonomy at time).

    I really don't know what's the problem there, I guess it could be related to some ID or classes which broke the ACF JQuery script – which could have references to original WordPress ID/classes or their checkboxes ID/classes – but mine is just a thought. In fact I saw your plugin add "radio-" term in Category box, maybe this is the problem. Anyway I can provide you all the further information you need.

    Thank you very much!

  5. helgatheviking
    Member
    Plugin Author

    Posted 1 year ago #

    Pietro,

    Thanks I understand much better now. I think you are correct, the different ID on my meta box probably isn't playing nicely with their script. I would have to test to see if I could do without that, but I know that I am using it for my plugin's scripts.

  6. Pietro Gregorini
    Member
    Posted 1 year ago #

    Ok Kathy, let me know if this could be resolved in some way.

    I don't know how can I help you. I'm just thinking: if you keep the original WordPress IDs and just replace the checkboxes with radio buttons (maintaing the same IDs even for them) would not your plugin work anyway and have less compatibility problems? If your plugin works with JQuery and use it for some tricks, couldn't you manage it though classes instead of IDs? Maybe my thoughts are totally wrong, don't blame me, I'm just telling you those things as a simple suggestion, like a brainstorming.. :)

    If this issue require too much work to test and upgrade your plugin, I could try to modify it for my needs, but I'd like to know some tricks to do it, for example understand how does it works (you know, is always a mess trying to figure out how a plugin works looking directly to the code).

    Thank you again!

  7. helgatheviking
    Member
    Plugin Author

    Posted 1 year ago #

    Looking at this again, I don't actually think I am relying heavily on the IDs for my javascript. However, the problem I am seeing is that I have to remove the default metabox for the taxonomy. Then when adding it back, as far as I can tell I have to change the ID or else, WP won't add it. If we can find a way around that, perhaps we can solve it.

    (you know, is always a mess trying to figure out how a plugin works looking directly to the code).

    lol... this depends on who is doing the looking and who wrote the code! I think mine is pretty clean (biased obviously). It creates a class instance for every taxonomy you want to use as radios and then repeats all the same actions... like removing the original metabox and adding the new one, adding the scripts, etc.

  8. Pietro Gregorini
    Member
    Posted 1 year ago #

    However, the problem I am seeing is that I have to remove the default metabox for the taxonomy. Then when adding it back, as far as I can tell I have to change the ID or else, WP won't add it.

    What about if you don't remove the metabox but, instead, remove each checkbox element through JQuery and replace each one with a radio button with the same ID? I know, it's a workaround which wouldn't work if JavaScript is disabled, but the whole WordPress dashboard require to have it enabled, so it wouldn't be a great problem.

  9. helgatheviking
    Member
    Plugin Author

    Posted 1 year ago #

    Umm... I'd really rather not re-write my entire plugin's scripts. Besides, I think I started off that way and had to adapt b/c it fell short somewhere. Plus more javascript seems like a recipe for more conflicts.

    How do you make an ACF metabox display contingent on category?

  10. Pietro Gregorini
    Member
    Posted 1 year ago #

    Since I can't include screenshots here, I uploaded them on my website and I let you see through links. In ACF there is a panel called "Rules" where you can set various conditions for the meta boxes to appear.

    I tried with categories:
    ACF > http://www.pietrogregorini.com/category_acf.png
    As shown in New Post > http://www.pietrogregorini.com/category_post.png

    And with taxonomies too:
    ACF > http://www.pietrogregorini.com/taxonomy_acf.png
    As shown in New Post > http://www.pietrogregorini.com/taxonomy_post.png

    Oh, don't be worried for the names of taxonomies, they are written in silly Italian.. ;)

  11. helgatheviking
    Member
    Plugin Author

    Posted 1 year ago #

    Well I couldn't figure out the admin side, but I looked in their code and found the problem in 5 seconds.

    // taxonomy / category
    	$('.categorychecklist input[type="checkbox"]').live('change', function(){
    
    		// vars
    		var values = [];
    
    		$('.categorychecklist input[type="checkbox"]:checked').each(function(){
    			values.push( $(this).val() );
    		});
    
    		acf.data.post_category = values;
    		acf.data.taxonomy = values;
    
    		update_fields();
    
    	});

    Their change script (that reacts to a change in term) is looking specifically for checkbox inputs and so won't fire on my radio inputs.

  12. Pietro Gregorini
    Member
    Posted 1 year ago #

    Wowowowowow! You're great Kathy! ^_^

    So, type="checkbox" could simply be substituted with type="radio" or, better, checking if the taxonomy/category use checkboxes or radio buttons and consequently use the right type, that's right?

    Do you think I should submit this issue to ACF team, so they may modify officially this without making my own version?

  13. helgatheviking
    Member
    Plugin Author

    Posted 1 year ago #

    I suppose? Certainly worth a shot.

    I tried using .on() (since .live() is deprecated) and couldn't quite get it to work. I think you might also need an .each() for each .checklist b/c my console log is telling me that it is picking up 2 values (the one from the regular list and the one from the popular terms list, since that one is changed via javascript and is probably happening "After" this change event.

  14. Pietro Gregorini
    Member
    Posted 1 year ago #

    Ok, I opened a thread in ACF support page, you can see it here.
    I mark this thread as "resolved" since the issue isn't related to your plugin.

    Thank you again for your support Kathy.
    I really appreciated it.

  15. helgatheviking
    Member
    Plugin Author

    Posted 1 year ago #

    You're welcome and good luck!

  16. lopo
    Member
    Posted 10 months ago #

    Hi,
    I stumbled in the same problem, tried to replicate Javascript behaviour for radiobuttons, but something prevented ACF to store values.
    It turns out that renaming every "radio_tax_input" to "tax_input" (as they were before, and as untouched checkbox are) works like a charm...

    Do you think that there are problems which may arise by removing "radio_" from the fields' names?

    Kudos for this very helpful plugin!

  17. helgatheviking
    Member
    Plugin Author

    Posted 10 months ago #

    As posted above:

    However, the problem I am seeing is that I have to remove the default metabox for the taxonomy. Then when adding it back, as far as I can tell I have to change the ID or else, WP won't add it. If we can find a way around that, perhaps we can solve it.

    RBfT should be saving the tax term info, so I'm not sure what the conflict with ACF is now.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic