2021-12-09

Tech Programing

程式人小天地

Table ‘postmeta’ doesn’t exist while it exists

1 min read


I am doing a $wpdb->query
to check whether the ticket_id already exists or not. If it exists do not perform any action if it does not exists perform wp_insert_post
Here is my code:

$emails = new FAQ_Email_reader;  
global $wpdb;
//Get all emails. 
$total =  $emails->total_msg(); 

    for ($j=1; $j <= $total; $j++) { 
       $mail =  $emails->get($j);

$post_array = array( 
        'post_content'  => $mail['body'],
        'post_title'    => $mail['header']->subject,
        'post_type'     => 'faqpress_email',
        'post_status'   => 'publish',
        'meta_input'    => array(
            'from'      => $mail['header'] ->fromaddress,
            'email_date'=> $mail['header'] ->Date,   // add post meta as many as you want
            'ticket_id' => $mail['header']->Msgno,
            ),
       );

Now my $wpdb code is as follows:

$msgNo = $mail['header']->Msgno; 
    $ticketid = 'ticket_id';
    $postmeta="postmeta" ;
    $query = $wpdb->get_row($wpdb->prepare("SELECT * FROM postmeta where meta_key = %d and meta_value = %d ", $ticketid ,$msgNo ));
    $results = $wpdb->get_results($query);

Here I am getting the following error:

WordPress database error: [Table 'faqpress.postmeta' doesn't exist]
SELECT * FROM postmeta where meta_key = 0 and meta_value = 2

How to solve this error?



Source link

資料來源:Stackoverflow

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *