Tag Info

Hot answers tagged

4

Yes, do an INNER JOIN, something like this should work: $values = $wpdb->get_col($wpdb->prepare(" SELECT meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id WHERE meta_key= %s AND {$wpdb->posts}.post_status='publish'" ,$metakey )); I changed ...


1

prepare() is used to escape the values for example in the WHERE-statement. Usually it is anticipated the table selection is "hardcoded". If you can't use for example $wpdb->posts or the other "table"-functions, you could whitelist the allowed tables and check if $table_name is on this white list: <?php $allowed_tables = array( $wpdb->prefix . ...


1

Well, first of all, you use where post_status = 'publish'. So you wouldnt need to explicitly tell the drafts not to show up by using wp_posts.post_status != 'draft' I think, your SQL says somthing like: Grab all posts which are published and not drafted and attached to term_id 17 OR grab all posts which are attached to term_id 18 OR grab all posts ...



Only top voted, non community-wiki answers of a minimum length are eligible