• Resolved Chris Rault

    (@connectr)


    Hi guys,

    I recently started using CMB2 for some of the more advance fields of our Wines and Grapes post type and I gotta say I’m really digging using it.

    One thing I haven’t been able to figure out, is how come the taxonomy terms in one of our repeatable field groups is not being associated with the taxonomy term.

    The taxonomy is for the different flavors associated with different wines. The catch is in some cases, the taxonomy term label is different. To cater for that, I created a repeatable field group, with the taxonomy term added as Select2 dropdown and an optional label override field. This is working great in the front-end (and backend too), but when I go to the flavors taxonomy, it shows no posts associated with any of the terms.

    Any ideas what I’m doing wrong? My next challenge is to output the fields (and other meta) as filters on the post index, but in order to do so, I need the taxonomy terms association working.

    Any ideas?

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Chris Rault

    (@connectr)

    Here is a pastie of the code I’m using to add the flavors meta:
    https://www.pastiebin.com/5b9fa70aac491

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Based on the code used, it looks like this is intended to save the chosen term(s) as post meta, however when you’re checking things, it sounds like you’re expecting it to have the terms set as one would when using the default term metaboxes, whether it be like the category one, or the tags one.

    This is actually a reverse issue of what we usually see when people use the taxonomy_* field types found at https://github.com/CMB2/CMB2/wiki/Field-Types where they are hoping to use the get_post_meta functions for display, but they hadn’t realized that those field types replace the default metaboxes.

    Does this sound about right for what you’re experiencing?

    Thread Starter Chris Rault

    (@connectr)

    Hi Michael,

    Thanks for taking the time to respond ??

    That’s right. I figured using the taxonomy field types would have a two way sync, outputting as normal meta fields, but still associating the term with the post.

    I considered adding a pivot table to handle the association, but that feels somewhat overkill, so I thought I’d check here first.

    Cheers,
    Chris

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    There’s no way that I know of, out of box, to have a field save to multiple places. It’s either going to be to post meta, as you’re seeing right now with your field setup, or to terms with the taxonomy_* field types.

    You would need to set up extra code, whether it be a pivot table as you mention, or intercept things upon save, and update extra data elsewhere. That last one would also be extra code.

    Specifically something like these filters https://github.com/CMB2/CMB2/blob/trunk/includes/CMB2_Field.php#L320-L354 could be used to intercept what data you’re saving, and you could use it to update term information, before returning null again, so that the post meta still saves as well.

    Thread Starter Chris Rault

    (@connectr)

    Gotcha.

    I tried updating the flavor_term field to the taxonomy_select field type, but that doesn’t seem to work in a repeatable field group, as all the values are set to the last one on save.

    The other catch is that the flavors are set on the wine_style post type, which is outputted inside of the wine post type. Each wine has multiple styles, each with their own flavor profile, so I think I’m going to have to rethink my approach.

    Thanks for your input ??

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Given that the taxonomy_* fields are meant to be a replacement for the default metabox for a taxonomy, there’s no reason it should be available as a repeatable field. It’d just be doing extra unneeded work if that were the case. You’re still going to want a more “generic” field type so that at least it saves as post meta.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Taxonomy terms not being set in repeatable field group’ is closed to new replies.