WordPress.org

Ready to get started?Download WordPress

Forums

Custom meta box on specific pages (3 posts)

  1. obidos
    Member
    Posted 1 year ago #

    Hello,

    I have created a custom meta box than shows on all pages. However, I only want the meta box to show on pages that have children. Parent pages.

    Any ideas?

    Thank you

  2. Phil
    Member
    Posted 1 year ago #

    Where you generated the meta box code (functions file or plugin), maybe try placing it inside (not tested this myself):

    function is_tree( $pid ) {
        if ( is_page() ) {
            return ( get_the_ID() == $pid || in_array( $pid, get_post_ancestors( get_the_ID() ) ) );
        }
      return false;
    }

    More info on get_post_ancestors... here.

  3. obidos
    Member
    Posted 1 year ago #

    Hi Phil and thank you for your reply.

    I am adding my custom meta within my functions file and here is the bit of code I have to add it to the pages:-

    function add_custom_meta()
    {
    	add_meta_box("subpages", "Include page in sub navigation", "get_pages_list", "page", "normal", "default");
    }
    add_action('add_meta_boxes', 'add_custom_meta');

    So it shows on all pages. I just need it on the top level parent pages.

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic