• Hello everyone,

    I would like to list the IDs name of all my pages included in a parent page. Not the number ID (for example 570) but the thing that I think is calling “post-slug” (the %postname%).

    For example, if my mother page is “Europe”, I would get the IDs of pages girls (France, Spain, Portugal, UK…)

    Do I need a plugin or is it possible by SQL query?

    Thank you, and sorry for my language I know I mak lot of mistakes when I write in English but I’m learning !

Viewing 3 replies - 1 through 3 (of 3 total)
  • Think you are looking for post_name

    <?php
    $args=array(
      'post_parent' => 93,
      'post_type' => 'page',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        echo '<p>post_name '. $my_query->post->post_name .'</p>';
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    [ moderated code fixed ]

    Thread Starter winny50

    (@winny50)

    Yes, after some research I am look for the postnames of those pages…

    Thank you for your answer but what do I do with it ? It’s not working include a page, not work in a php page too.

    Note–I had to make a fix to that code…

    You would put that inside a Page Template and change 'post_parent' => 93, to 'post_parent' => $posts[0]->ID,

    If you just want the SQL then here it is

    SELECT   wp_posts.* FROM wp_posts
    WHERE 1=1  AND wp_posts.post_parent = 93
    AND wp_posts.post_type = 'page'
    AND (wp_posts.post_status = 'publish')
    ORDER BY wp_posts.post_date DESC

    Related:
    wpdb
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to list id page name under parent page ?’ is closed to new replies.