0

I am trying to run a query from my functions.php inside a shortcode

See code

function nrl_listing_page($args) {
    global $wpdb;
    $wpdb->show_errors( true );
    $properties = $wpdb->wp_nrl_properties;
    $sql = " SELECT * FROM  $roperties" ;
    $query = $wpdb->get_results($sql, ARRAY_A );

    if (is_null($results)) {
    echo "Big Fat Falure!!!!";
} else {
    echo $query;
   echo "Success!!!";
}
}
add_shortcode( 'nrl_listing_creator', 'nrl_listing_page' );

I get this error when I try to use the shortcode in a page

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1] SELECT * FROM

What am I doing wrong?

  • probably $wpdb->wp_nrl_properties is not defined and so your query is SELECT * FROM which is not valid because no table has been selected. – s t Apr 26 '17 at 20:40
  • How do I fix that? – Top-Bot Apr 26 '17 at 21:05
  • Try var_dump($roperties); also try $sql = " SELECT * FROM" . $roperties; – Yamona Apr 26 '17 at 21:10
  • I also noticed typo error instead of $properties you have $roperties" – Yamona Apr 26 '17 at 21:12
  • Still no dice, the same error persists – Top-Bot Apr 26 '17 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.