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;
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.

  • still the current page displayed in the list – user103182 Feb 2 '17 at 7:21
  • Try edited answer – Aniruddha Gawade Feb 2 '17 at 8:07
  • still not working, the current page is not excluded in the child pages list – user103182 Feb 2 '17 at 9:11
  • Is your $current_post_id value corect? – Aniruddha Gawade Feb 2 '17 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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