Get children of parent with MySQL SELECT query


/ Published in: PHP
Save to your folder(s)

Plugin gets child pages of parent in Wordpress. You'll need to pass the parent ID but this isn't difficult to figure out programmatically if needed, either.


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. // Include Wordpress framework/API
  4. require_once( '/path/to/wp-load.php' );
  5.  
  6.  
  7. // Get parents (level one)
  8. $items_level_one = $wpdb->get_results(
  9. 'SELECT
  10. *
  11. FROM
  12. wp_posts
  13. WHERE
  14. post_type = "Page" AND
  15. post_status = "Publish" AND
  16. post_parent = "[put parent id here]"
  17. ORDER BY
  18. menu_order,
  19. post_title',
  20. ARRAY_A
  21. );
  22.  
  23. print_r($items_level_one);
  24.  
  25. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.