I need to query the database on add_action( 'init', '...') to find post ids with the field 'product_discount_option' set to true.
I know at least one of my product posts have the field 'product_discount_option' set to true. However when i run the SQL query below and var_dump it outputs an empty array , array(0) { } ..
add_action( 'init', 'retrieve_product_ids');
function retrieve_product_ids(){
global $wpsc_cart, $wpdb;
$product_ids = $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM `".WPSC_TABLE_META."` WHERE `meta_key` = 'product_discount_option' AND meta_value = true" ) );
var_dump($product_ids);
}
The field 'product_discount_option' has been setup using the Advanced Custom Fields Plugin. The posts are WPeC custom post types, post_type = 'wpsc-product'.
I'm new to SQL queries, sorry if i've missed anything in the question.
thanks Cam
var_dump
with your query string alone-- none of the$wpdb
stuff. Something likevar_dump("SELECT object_id FROM....")
Does the query look sane?sb_wpsc_meta
WHEREmeta_key
= 'product_discount_option' AND meta_value = true"