Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • Go check global variables provided from WordPress such as $wpdb. Why you define $db when you already have $wpdb ? Also $db->tb_posts should be $wpdb->posts same for the meta. If you insist on using your own keep in mind that you must whitelist and escape table names manually before inserting them into your query. You will be flaged for stuff like that if you dont follow the guidelines. Commented Sep 29, 2025 at 7:54
  • @Snuffy can you guide me which type of escape I required here? Commented Sep 29, 2025 at 8:21
  • If you provide some code to look up. WIth this its unclear what you define how and so on. Commented Sep 29, 2025 at 8:47
  • @Snuffy $sql_orders = $wpdb->prepare( "SELECT p.* FROM {$db->tb_posts} p INNER JOIN {$db->tb_postmeta} pm ON p.ID = pm.post_id AND meta_key = %s AND (meta_value = %d OR meta_value like '%s')", '_user_id',$user_id,$user_id_str); $sql = $sql_orders . $sql_rest; $order_posts = $db->wpdb->get_results($sql); # You cannot add variables like "$db->tb_posts" directly to the SQL query. # Using wpdb::prepare($query, $args) you will need to include placeholders for each variable within the query and include the variables in the second parameter. Commented Sep 29, 2025 at 8:58
  • Please edit your question and add the code. Dont post in comments. Commented Sep 29, 2025 at 9:25