check if page have children, but not attachment

I am trying to display a sub-menu with the sub-pages of a parent, if you are on the parent page, and the siblings if you are on one of the child pages, but the problem is that if the page have a featured image is recognized az a parent. this is the code I use:

    // check if page have children
        $children = get_children( get_the_ID() );
        if ( ! empty($children)) {
            echo 'ul class=submenu';
            wp_list_pages(array(
                'child_of' = $post-ID,
                'title_li' = 0,
                'item_spacing' = 'discard'
                // 'exclude' = $post-ID
            ));
            echo '/ul';
        } else if ($post-post_parent){
            echo 'ul class=submenu';
    // get a back link to the parent
            echo 'li class = bold parentbuta href =' . get_permalink($post-post_parent) . '' . get_the_title($post-post_parent) . '/a/li';
            wp_list_pages(array(
                'child_of' = $post-post_parent,
                'title_li' = 0,
                'item_spacing' = 'discard'
                // 'exclude' = $post-ID
            ));
            echo '/ul';
        } else {
            echo 'div class=dunga-albastra/div';
        }

the problem is that I do not get to the second else-if, if the child page have an atachment.

Topic get-children php Wordpress

Category Web


You should specify the post_type for the get_children() function, which can be one of attachment, page, revision or any and considered to be any by default:

$children = get_children( array( 'post_parent' => get_the_ID(), 'post_type' => 'page' ) );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.