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.
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.
Share Improve this question asked Apr 29, 2020 at 13:54 user2026121user2026121 32 bronze badges 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. – Karthick Commented Apr 29, 2020 at 15:06
1 Answer
Reset to default 0The 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 ();