0

I have this query to do in my code:

  function get_item($id){
    global $wpdb;

    $post_id_query = "SELECT * FROM wp_postmeta WHERE post_id = ". $id ." AND meta_key LIKE '%main%'";
    $call_post_id_call = $wpdb->get_results($wpdb->prepare($post_id_query));

    return $call_post_id_call;
  }

  $main_item = get_item(34487);

If I run SELECT * FROM wp_postmeta WHERE post_id = 34487 AND meta_key LIKE '%main%' on my DB it works...

I'm not very keen on wordpress to be honest.

1
  • Try to run print $wpdb->last_query; before the return call and check the exact query being executed. Also, couldn't see any issues in the script, it should work if the query works in you DB. Commented Apr 29, 2020 at 15:06

1 Answer 1

0

The following script will help you to identify if there any error exists in the query.

$wpdb -> show_errors ();
$call_post_id_call = $wpdb->get_results($wpdb->prepare($post_id_query));
$wpdb -> print_error ();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.