Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

taxonomy_select default being stomped by get_object_terms #572

Closed
wilrevehl opened this issue Jan 26, 2016 · 4 comments
Closed

taxonomy_select default being stomped by get_object_terms #572

wilrevehl opened this issue Jan 26, 2016 · 4 comments
Labels

Comments

@wilrevehl
Copy link

Hi Justin, et all,

Thanks for much for your sharing hard work on CMB2. It's definitely the best out there, we applaud you.

I'm having an issue setting default on taxonomy_select. At the time of writing, line 665 of includes\CMB2_Types.php::$saved_term has a ternary with $this->get_object_terms() taking precedence over default. get_object_terms() gets the select by using something stored as a cmb-cache. This probably has its purpose. Unfortunately, I'm trying to use taxonomy_select with dynamic data from a callback to set the default. This is important because it allows the same form for New and Edit. That other cached value is causing the intended default (from data specific to the post) to be ignored.

I'm going to see if I can workaround this using the filters. My use may be an edge case, but thought you should know this feels like an unintended consequence. Thanks. Keep rocking.

@wilrevehl
Copy link
Author

Update: I noticed the ternary condition for $saved_term favors the $names failover because the result of $names is almost always going to return the terms the field is set to use. It's therefore nearly impossible a default setting would ever work for this, unless you added something like:

$saved_term = is_wp_error( $names ) || empty( $names ) || $this->field->args( 'default' ) ? $this->field->args( 'default' ) : $names[key( $names )]->slug;

@tw2113
Copy link
Contributor

tw2113 commented Mar 14, 2016

Any updates or progress made on this @wilrevehl ?

@wilrevehl
Copy link
Author

Oh, I never made a fork contribution since I never heard back and the issue was small. I'm not really a GIT user as it is. Nothing has changed in CMB2 taxonomy_select. $names is still the sole ruler of the conditional.

@tw2113
Copy link
Contributor

tw2113 commented May 15, 2016

Closing early as Justin's commit above states it fixes this issue.

@tw2113 tw2113 closed this as completed May 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants