0

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=2143&exclude='.$current_post_id.'")):
    if($title)
        echo $before_title . $title . $after_title;
        wp_list_pages("title_li=&child_of=2143&exclude='.$current_post_id.'");
endif;

4 Answers 4

0

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.

4
  • still the current page displayed in the list
    – user103182
    Feb 2, 2017 at 7:21
  • Try edited answer Feb 2, 2017 at 8:07
  • still not working, the current page is not excluded in the child pages list
    – user103182
    Feb 2, 2017 at 9:11
  • Is your $current_post_id value corect? Feb 2, 2017 at 9:57
0

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

0

This always works for me:

$current_post_id = get_the_ID();
$child_pages = wp_list_pages( array(
    'title_li' => '',
    'sort_column' => 'post_date',
    'sort_order' => 'desc',
    'echo' => 0,    
    'exclude'  => ($current_post_id)
    )
);
0

I know its a little late answer but hoping it will be helpful for someone

    $parent_id = wp_get_post_parent_id( $post->ID );

    wp_list_pages( array(
        'title_li' => '',
        'child_of'    => $parent_id,
        'depth'     => 1,
        'exclude'  => $post->ID
        )
    ); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.