Advanced Location Rule: for different post types

Support Meta Box AIO Advanced Location Rule: for different post typesResolved

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #48266
    PTPT
    Participant

    Hi,

    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?

    #48271
    PeterPeter
    Moderator

    Hello,

    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/

    #48273
    PTPT
    Participant

    Hi,

    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?

    #48277
    PeterPeter
    Moderator

    Hello,

    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/

    #48279
    PTPT
    Participant

    I'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.

    #48288
    PeterPeter
    Moderator

    Hello,

    > "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.

    #48290
    PTPT
    Participant

    Got it and thanks.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.