Advanced Location Rule: for different post types
Support › Meta Box AIO › Advanced Location Rule: for different post typesResolved
- This topic has 6 replies, 2 voices, and was last updated 4 weeks, 1 day ago by
PT.
-
AuthorPosts
-
May 16, 2025 at 5:03 PM #48266
PT
ParticipantHi,
I have a custom field group that wants to be applied to:
1. All "Events" (custom post type)
2. Some "Pages", e.g. Page "One", Page "Two"But it seems that I only set to either one of the following scenarios:
a. All "Events" and all "Pages"
b. The selected posts (in the advanced location rule) e.g. "One" and "Two" from all "Events" and all "Pages". That means it will not show on "Events" at all.Is that the case?
If so, how can I achieve my goal?May 17, 2025 at 5:40 PM #48271Peter
ModeratorHello,
Yes, in the builder, you can select all Events and Pages post to show the field group. If you want to show the field group on some specific posts, please use the code to register the field group. Following the documentation
https://docs.metabox.io/extensions/meta-box-include-exclude/May 17, 2025 at 6:48 PM #48273PT
ParticipantHi,
I tried the following filter but it doesn't work.
add_filter( 'rwmb_show_text-field-group', function( $show, $meta_box ) { $post_type = get_post_type(); $post_id = isset( $_GET['post'] ) ? $_GET['post'] : null; $post_id_array = array(40,271,333,335,273); if ( ( $post_type == 'book' ) || ( ( $post_type == 'page' ) && ( in_array($post_id, $post_id_array) ) ) ) { $show = true; } return $show; }, 10, 3 );
Do I have to remove the conditions I set through the included/exclude extension?
May 18, 2025 at 8:47 PM #48277Peter
ModeratorHello,
Yes, you can register the custom fields with code and use the extension include/exclude to add the post IDs to the meta box settings. For example:
add_filter( 'rwmb_meta_boxes', 'prefix_include_exclude_demo' ); function prefix_include_exclude_demo( $meta_boxes ) { $meta_boxes[] = array( 'title' => 'Include Meta Box', 'include' => array( // List of post IDs. Can be array or comma separated. Optional. 'ID' => array( 40,271,333,335,273), ...
Please follow the documentation https://docs.metabox.io/extensions/meta-box-include-exclude/
May 19, 2025 at 12:14 AM #48279PT
ParticipantI've tested, and they're not working for me.
I know that "I can select all Events and all Pages posts to show the field group" and "I can use the extension include/exclude to add the post IDs". But can I achieve BOTH at the same time, i.e. show the field group to ALL Events posts and SOME Pages posts? If it's not possible, please tell me so. Then I won't waste any more time.
May 19, 2025 at 11:29 PM #48288Peter
ModeratorHello,
> "I can select all Events and all Pages posts to show the field group" and "I can use the extension include/exclude to add the post IDs". can I achieve BOTH at the same time?
In short, no. You can select all Events and Pages in the builder (UI). But if you want to add the post IDs to the include/exclude settings, you have to use the code.
> show the field group to ALL Events posts and SOME Pages posts
Please follow my reply above to use the code to register the custom fields, add some post IDs to the include/exclude settings to see how it works. Then you can add ALL Events post IDs and some Pages IDs.
If you are not familiar with coding, we offer a customization service with an extra fee. Please contact us here https://metabox.io/contact/ for more details.
May 20, 2025 at 9:46 AM #48290PT
ParticipantGot it and thanks.
-
AuthorPosts
- You must be logged in to reply to this topic.