Forums › Forums › Search & Filter Pro › Is it possible to combine multiple meta keys into one post meta field dropdown?
Tagged: combining meta keys, post meta field
- This topic has 6 replies, 2 voices, and was last updated 7 years ago by
Anonymous.
-
Anonymous(Private) July 11, 2018 at 5:08 pm #182361
I was thinking that originally, but might get confusing or annoy my client. If they were in the Resources CPT, they wouldn’t ever select blog post, as those are create in the Posts post type section. And if they were creating blog posts in the Posts post type section, they would never select anything other than blog post from the resources type acf field.
That was why I was hoping there was a way to combine meta keys in a single Post Meta field dropdown.
Anonymous(Private) July 11, 2018 at 5:21 pm #182363I probably should specify that the Resources Type ACF field does NOT contain an option for Blog Posts now. My last comment was under the assumption that I would add it to the Resource Type ACF field in order to add the field group to both Resources and Posts Post type. AS of now, the Resources Type ACF field only appears on the Resources CPT
Anonymous(Private) July 11, 2018 at 9:33 pm #182369So I ended up figuring out a hacky work around. If anyone else runs into this situation what I did was add Blog Posts to my Resource Type ACF Field (changed from checkbox to select field) as the first option and included it on both Posts and Resources post types.
Then I used the following action:
add_action('admin_head', 'hide_checkbox_option'); function hide_checkbox_option() { // Hide Resource Type Field Group if( get_post_type() == 'post' ) { ?> <style> #acf-group_5b465bd8ba093 { visibility: hidden; } </style> <?php } // Hide first <option>, which is Blog Post if( get_post_type() == 'resources' ) { ?> <style> #acf-field_5b465be2c6c7f option:first-child { display: none; } </style> <?php } }
This basically hides the field group altogether on blog posts, and since blog post is the first option, it will automatically be selected for each newly created blog post even though the user will never see it.
Then it’s hiding the first option in the Resource Type select field on the Resources CPT. So that way the client doesn’t get confused seeing Blog post as an option.
Like I said, I realize this is super hacky, and I would be open to other suggestions. But I’ve tested it out and it works, so will have to do for now.
Trevor(Private) July 12, 2018 at 6:58 am #182380Alternatively, on the WP ‘save_post’ (https://codex.wordpress.org/Plugin_API/Action_Reference/save_post), you could automatically add an action to add the post_meta, so that the user does not have to select it?
-
AuthorPosts