Can I run multiple queries with $wpdb->prepare?

Outside of subqueries, MySQL will only process 1 query at a time. When running sql statements through phpmyadmin, it just executes 1 query after the other. To do the same thing in WordPress, it appears you just use 1 query per $wpdb object (those can have subqueries if desired, but not what’s needed here).

Hide Post comments when displayed via WP_Query

The problem You must remember to call the core function wp_reset_postdata(), after your while loop, to restore the global $post object. The comment form is relying on that object, that you override with your $queryPosts->the_post() call. Note that the extract() isn’t recommended, check this answer by @toscho, for example. Removing comments To remove the comment … Read more

How to display custom field on homepage

Try this: if ( ! function_exists( ‘customField’ ) ) : function customField($name, $id=false, $single=false){ global $post_type, $post; $name=trim($name); $prefix=”; // only if you need this $data=NULL; if($id!==false && !empty($id) && $id > 0) $getMeta=get_post_meta((int)$id, $prefix.$name, $single); else if(isset($post->ID) && $post->ID > 0) $getMeta=get_post_meta($post->ID,$prefix.$name, $single); else if(‘page’ == get_option( ‘show_on_front’ )) $getMeta=get_post_meta(get_option( ‘page_for_posts’ ),$prefix.$name, $single); else … Read more

Custom Query to display posts with custom field

As @jdm2112 implied, WP_Query for your 2nd display is preferred over query_posts. Try using WP Query for your first display as well. It would look something like: <?php $args = array( ‘post_type’ => ‘cars’, // or whatevr the custom post type is ‘post_status’ => ‘publish’, ‘meta_query’ => array( array( ‘key’ => ‘wpcf-featured’, ‘value’ => true, … Read more

$wpdb->insert inserting two rows in database

Try something like this function insert_data_into_table () { global $wpdb; $table_name = $wpdb->prefix . “your_table_name”; //Check if table exists if($wpdb->get_var(“show tables like ‘$table_name'”) != $table_name) : //if not, create the table $sql = “CREATE TABLE ” . $table_name . ” ( (…) ) ENGINE=InnoDB;”; require_once(ABSPATH . ‘wp-admin/includes/upgrade.php’); dbDelta($sql); else: foreach($emails as $mail): $insert = “INSERT … Read more