PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, May 15, 2022

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

 May 15, 2022     sql, wordpress     No comments   

Issue

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


Solution

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


Answered By - Dotsquares
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing