Custom Fields
Re-Envisioned
Support Meta Box Include Exclude Feature Request: Advanced location rules -> limit display to home/front-page

  • Creator
    Topic
  • #28528
    Resolved Aaron 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')],
            ],

    ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #28549
    Long 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 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 Kessler
    Participant

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

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