最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to get the custom post data using post id in WordPress?

programmeradmin4浏览0评论

I am using WordPress, I have to get the custom post type data using post id and I tried the below code but I am getting the error

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '* FROM WHERE 1=1 AND .ID = 972 AND .post_type = 'test' AND ((.post_s...' at line 1]

I am getting query and array output below.

 Array ( [p] => 972 [post_type] => test [post_status] => publish [order] => DESC ) SELECT .* FROM WHERE 1=1 AND .ID = 972 AND .post_type = 'test' AND ((.post_status = 'publish')) ORDER BY .post_date DESC 

I am using the below code

 function postData($wpdb, $parentsdata){
        $args = array(
                      'p' => $parentsdata['utm_id'],
                      'post_type' => 'test',    
                      'post_status' => 'publish',
                      'order'      => 'DESC'
    );
    
      $related = new WP_Query($args);
      print_r($args); // checking parameters
      echo $wpdb->last_query; // query
         
         //$my_post = get_post($parentsdata['utm_id']);
        //echo $my_post->post_title;
    
         wp_reset_query();
     }
发布评论

评论列表(0)

  1. 暂无评论