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 multicheck values and $cmb->get_sanitized_values( $_POST ); #538

Closed
jondcampbell opened this issue Dec 4, 2015 · 11 comments
Closed

Comments

@jondcampbell
Copy link

I have a frontend form.

When the form submits my text, wysiwyg, and taxonomy_multicheck fields are all in the $_POST.

When I look at the dump of $cmb->get_sanitized_values( $_POST ) all my taxonomy_multicheck values are gone, so I can't process them and save the submission. My text and wysiwyg fields survive the get_sanitized_values()

@jtsternberg
Copy link
Member

The taxonomy fields are not intended to provide an arbitrary list of terms to pick from, but are intended to be a replacement for the default taxonomy metaboxes. I.e. they are meant to set the taxonomy terms on an object. Any other use of these types will be hacky and/or buggy. I suggest looking at building a custom field type for this: https://github.com/WebDevStudios/CMB2/wiki/Tips-&-Tricks#a-dropdown-for-taxonomy-terms-which-does-not-set-the-term-on-the-post

@jondcampbell
Copy link
Author

I am using the taxonomy_multicheck fields for my custom taxonomies to set the taxonomy terms on my custom post. I am trying to accomplish a frontend implementation of what the default taxonomy metaboxes do on the backend, but when the values are sanitized the taxonomy terms that were selected using the field are gone.

@jtsternberg
Copy link
Member

are you using the front-end form to save an existing post, or create new? If saving an existing post, there's no reason you should be using get_sanitized_values. You should be using something similar to this: https://github.com/WebDevStudios/CMB2-Snippet-Library/blob/master/front-end/cmb2-metabox-shortcode.php

@jondcampbell
Copy link
Author

I am creating a new resource.

For testing I am dumping the $_POST and then dumping the $_POST after it has been sanitized.
The title and content survive sanitization but the taxonomy_multicheck fields do not.

@jtsternberg
Copy link
Member

Again, the taxonomy fields are not intended to be used the way you are using them. I suggest: https://github.com/WebDevStudios/CMB2/wiki/Tips-&-Tricks#a-dropdown-for-taxonomy-terms-which-does-not-set-the-term-on-the-post

@jondcampbell
Copy link
Author

I am having trouble understanding how the taxonomy_multicheck field is supposed to be used, if it isn't for setting the taxonomy terms for my post.

@jondcampbell
Copy link
Author

Sorry Justin,
I am not trying to be a jerk I am just hitting a frustrating level of not understanding why this doesn't work.

Lets break it down like this
A. Is it wrong to use a taxonomy_multicheck field to select some taxonomy terms that I want a post to be associated with?
In this case I have a bunch of ministry resources and we have custom taxonomies for the resource type, resource season, and resource age group. Each of those is a taxonomy and I want them to be able to have our resources be properly taxonomized under those terms.

B. Should I expect taxonomy_multicheck values to survive get_sanitized_values()?

C. I am currently assuming that as I process the frontend form I have to implement code that will save the values for my taxonomy_multicheck fields, CMB2 is not going to save values for me automatically, which is why I was thinking it should go through the sanitization and then I will save the terms for the post.

@tw2113 tw2113 self-assigned this Aug 10, 2016
@tw2113
Copy link
Contributor

tw2113 commented Aug 11, 2016

@jondcampbell Is this still presenting an issue for you? Perhaps it has since been resolved by the fields working as expected finally, or by some sort of hotfix/change in what you're using for the frontend?

Justin from the looks of things, he was using the field types properly, wanting to set terms for the post objects, as opposed to saving term information to post meta. The data wasn't getting past the sanitization functions though.

@jondcampbell
Copy link
Author

jondcampbell commented Aug 11, 2016

Hey @tw2113 ,

Ended up switching to ACF for this project so this Issue doesn't really matter to me anymore.

@tw2113
Copy link
Contributor

tw2113 commented Aug 11, 2016

No worries, thanks Jon.

Leaving open for further investigation

@tw2113 tw2113 added the bug label Aug 11, 2016
@jtsternberg
Copy link
Member

As a follow-up, since Jon reminded me of this thread today :), basically, the tax fields use the same field name structure that WP admin expects for the built-in tax-term UI, so WP saves them for us for free (CMB2 doesn't handle the term-setting/saving bit). If you use those tax fields outside of the post edit screen, WP won’t do the work for you, so you're on your own. You’re right in that it should likely have a fallback saving mechanism in scenarios where the fields are not being used in the post-edit screen (or at least document this limitation in the wiki until it can be addressed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants