Feature Request: Advanced location rules -> limit display to home/front-page

Support MB Include Exclude Feature Request: Advanced location rules -> limit display to home/front-pageResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #28528
    Aaron KesslerAaron Kessler
    Participant

    While using the visual custom fields advanced location rules editor I can't limit the custom field display to the home.php and/or front-page.php. Could you add functionality, to limit the locations to those pages in the visual editor, like so:

    'include' => [
                'relation' => 'OR',
                'ID' => [get_option('page_for_posts')],
            ],
    'include' => [
                'relation' => 'OR',
                'ID' => [get_option('page_on_front')],
            ],

    ?

    #28549
    Long NguyenLong Nguyen
    Moderator

    Hi Aaron,

    Thank you for getting in touch.

    If you use the Builder, you can navigate to the Settings tab > Advanced location rules > Select Custom and pass the custom function name to check if the page is frontpage (set in Settings > Reading) or not. For example:

    function get_frontpage_id() {
        $post_id = null;
        if ( isset( $_GET['post'] ) ) {
            $post_id = intval( $_GET['post'] );
        } elseif ( isset( $_POST['post_ID'] ) ) {
            $post_id = intval( $_POST['post_ID'] );
        }
        return ( $post_id == get_option('page_on_front') ) ? true : false;
    }

    Screenshot https://share.getcloudapp.com/5zuYpLG2. Get more details on the documentation https://docs.metabox.io/extensions/meta-box-include-exclude/#settings

    #28584
    Aaron KesslerAaron Kessler
    Participant

    Thank you for the reply, I got stuck on how to get a true/false value for the callback. I will try this.

    #28766
    Aaron KesslerAaron Kessler
    Participant

    It works. However, it won't, if you like to check for more than one callback.

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