Make one query for adding entries to database

Is there a $wpdb method available that will allow me to create the query, by looping through my query, and then execute it once I’m out of that loop? If you and your loop can construct the proper SQL, then use $wpdb->query. You can run any query you want with that, so whatever version of … Read more

What’s wrong with my $wpdb prepare?

These look like 2 separate questions. The first I think is a single vs double quotes issue: Try this: $html=””; foreach ( $recent_across_network as $post ) { $html .= ‘blog_id, ‘.$post->ID.’ ) . ‘”>’ . $post->post_title . ”; } $html .= ”; The line in the foreach is putting $post->ID in single quotes which won’t … Read more

How to retrieve elements from another table in a SQL query?

With a WP_Query() you can have all of them what you want in an easy way. See all the arguments available in the Codex. With the following code, we are grabbing all(-1) the posts from wp_posts table, and using the post ID we are grabbing the postmeta items. <?php $productquery = new WP_Query( array( ‘post_type’=>’wpcproduct’,’post_status’=>’publish’,’posts_per_page’=>-1 … Read more

You have an error in your SQL syntax – Help with query

If that is the error, a couple of things could be going on. The part that uses ‘require’, ‘require_once’ and ‘include’ is not likely correct in the code. Each of these code statements should end with a semi-colon [;] not a comma [,] hh3_ I expect is the table prefix initially used in your database. … Read more

Select query for a login

You can use wp_signon function Here is an example $creds = array(); $creds[‘user_login’] = ‘example’; $creds[‘user_password’] = ‘plaintextpw’; $creds[‘remember’] = true; $user = wp_signon( $creds, false ); if ( is_wp_error($user) ) echo $user->get_error_message();

Error when using setup_postdata()

You are getting the error because, by default, wp_get_recent_posts returns an array of posts (due to backward compatibilty) and not the required WP_Post object which is required to setup the template tags. Look at the source code, and you will see that wp_get_recent_posts is a simple wrapper function for get_posts (which is just a wrapper … Read more

How select a specific query when setting offset?

If you only wish to effect the one, single query then just can pass the offset argument through the arguments array. $offset = 1; $ppp = 3; if ( $query->is_paged ) { $page_offset = $offset + ( ($query->query_vars[‘paged’]-1) * $ppp ); } blog_items = array( ‘post_type’=> ‘post’, ‘paged’ => $paged, ‘posts_per_page’=> $ppp, ‘status’ => ‘publish’, … Read more