Forums Forums Search & Filter Pro Is it possible to combine multiple meta keys into one post meta field dropdown?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Trevor
    #182357

    ACF group settings should allow you to add that group and the fields in it to the Posts post type as well. Would that work for you?

    Anonymous
    #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
    #182363

    I 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
    #182369

    So 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
    #182380

    Alternatively, 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?

    Anonymous
    #182397

    Thanks Trevor, as always, you’ve been super helpful!

Viewing 7 posts - 1 through 7 (of 7 total)