Home > Mobile >  How to extract ID from WP_POST table by POST_PARENT ID and POST_TYPE in WordPress?
How to extract ID from WP_POST table by POST_PARENT ID and POST_TYPE in WordPress?

Time:05-13

How to extract ID from WP_POST table by POST_PARENT ID and POST_TYPE in WordPress?

Plese see this image for better understanding >> Click here

CodePudding user response:

According to your screenshot image, we have extracted the post id. you can use this code.

<?php
// Table Name Define
$posts_table = $wpdb->prefix.'posts';

// Get result wp_posts table using table column
$result = $wpdb->get_results ( "SELECT `ID`, `post_parent`, `post_type` FROM $posts_table WHERE 1 ");

// This loop print the data
foreach($result as $post_data){

//filter data have a post_parent id and post_type.
if($post_data->post_type === 'lesson' || $post_data->post_parent === '12'){
    // print the post id
    echo $post_data->ID;
    }
}
?>
  • Related