Support » Plugins » Hacks » $wdpv returning nothing when using it via AJAX plugin.

  • Good day, I have a problem with my plugin because $wdpb returns an error when trying to do any query, my code is as follows:

    function search_engine_callback() {
    	global $wpdb;
    	$keyword = addslashes($_POST['keyword']);
    	//Get all related posts from the WP db...
    	$wpdb->show_errors();
    	$res = $wpdb->get_results("SELECT id, post_title FROM wp_posts  WHERE post_title = '$keyword'", 'ARRAY_A');

    And it shows me this error:

    WordPress Database Error: [] and the previous query.

    All works fine in the AJAX function but the query doesn’t return anything (No matter which query you add) it always return an empty [] as error.

    Any suggestion?

    Thanks in advance!

Viewing 1 replies (of 1 total)
  • Remove the quotes around ARRAY_A and it should be OK.

    I would suggest you use wpdb->prepare to avoid SQL injection attacks, rather than the extra stripslashes. E.g.

    $sql = “SELECT id, post_title FROM wp_posts WHERE post_title = %s”;
    $res = $wpdb->get_results($wpdb->prepare($sql, keyword),ARRAY_A);

Viewing 1 replies (of 1 total)
  • The topic ‘$wdpv returning nothing when using it via AJAX plugin.’ is closed to new replies.