Querying on specific WordPress table?

3

How do I query a WordPress in a specific table, which is: wp_dd_spg_galleries ?

I already have the gallery ID, I tried to make this query, but it does not return anything:

$query = "SELECT * FROM wp_dd_spg_galleries WHERE id = ".$idGaleria;
$idGal = $wpdb->query($wpdb->prepare($query));
    
asked by anonymous 17.04.2014 / 22:52

1 answer

4

The $wpdb->query() will only return the number of columns affected or false if nothing happens, so in case you should use $wpdb->get_results() .

I also recommend you use {$wpdb->prefix} to get the bank prefix that will not always be wp_ .

In addition to using $wpdb->prepare() in the wrong way, it works as printf() and this is how it will escape the data.

Here's the correct way to make your query:

$idGal = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}dd_spg_galleries WHERE id = %d", $idGaleria ) );
    
17.04.2014 / 23:49