如何在 WordPress 中通过 POST_PARENT ID 和 POST_TYPE 从 WP_POST table 中提取 ID?

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

如何在 WordPress 中通过 POST_PARENT ID 和 POST_TYPE 从 WP_POST table 提取 ID?

Plese see this image for better understanding >> Click here

根据您的截图,我们提取了post id。你可以使用这个代码。

<?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;
    }
}
?>