List child pages, exclude the current page

I'm trying to display the child pages of a parent page, this is working. But when I tried to exclude the current page in the list where the child pages displayed, it's not working.

How to fix this?

$current_post_id = $post-ID;
if(wp_list_pages("title_li=child_of=2143exclude='.$current_post_id.'")):
    if($title)
        echo $before_title . $title . $after_title;
        wp_list_pages("title_li=child_of=2143exclude='.$current_post_id.'");
endif;

Topic exclude child-pages Wordpress

Category Web


How about using

$args = array(
    'post_parent' => 2143,
    'post_type'   => 'any', 
    'numberposts' => -1,
    'post_status' => 'any' 
);
$children = get_children( $args );

https://codex.wordpress.org/Function_Reference/get_children


Looks like a syntax error to me. Try:

wp_list_pages("title_li=&child_of=2143&exclude=$current_post_id")

OR

wp_list_pages("title_li=&child_of=2143&exclude=".$current_post_id)

Also I will suggest to pass parameters as array instead of a string, for better debugging.

wp_list_pages( array(
    'child_of'    => 2143,
    'exclude'  => array( $current_post_id ),
); 

Make sure $current_post_id is giving proper value.

About

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