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

WPDB query – decrypting DB data

It’s just serialized, in WordPress, you can run maybe_unserialize and get back the variable/array. $crosssells = $wpdb->get_results( “SELECT * FROM $wpdb->postmeta WHERE _crosssell_ids <> ” ” ); $array = maybe_unserialize($crosssells); However, there are built in functions to retrieve posts based on meta information. You can use get_posts to retrieve the posts and get_post_meta to retrieve … Read more

Get published posts and pages?

Don’t use pure SQL if you don’t have to. WordPress provides a useful and relatively solid class for retrieving post data. Use it. $args = array( ‘post_type’ => array(‘post’,’page’), ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘ignore_sticky_posts’ => true, ); $qry = new WP_Query($args); // Show post titles foreach ($qry->posts as $p) { echo $p->post_title; } … Read more

wpdb->insert and stripslashes against sql injection

If you check out the source for the $wpdb->insert( $table, $data, $format) method you will find this comment: Data to insert (in column => value pairs). Both $data columns and $data values should be “raw” (neither should be SQL escaped). so you shouldn’t need to do the SQL escape yourself on the data. As far … Read more

WordPress database error – Error in SQL syntax – I can’t identify any error?

You want the query to look like this: SELECT email FROM wp_my_users WHERE email=”[email protected]” instead of this: SELECT email FROM ‘wp_my_users’ WHERE email=”[email protected]” So try to construct your query with: $sql = “SELECT email FROM {$my_table_name} WHERE email = %s”; $result = $wpdb->get_var( $wpdb->prepare( $sql, $email_address ) ); where you don’t need to escape the … Read more

$wpdb select date range of posts

You basically have the answer, just add $date2 to the inner sql where clause: AND p.post_date > ‘$date2’ to get last week. To get a particular week, use AND p.post_date < ‘$date1’ AND p.post_date > ‘$date2’ where eg $date1 = date(‘Y-m-d’, strtotime(‘2014-07-04 +1 days’)); $date2 = date(‘Y-m-d’, strtotime(‘2014-07-04 -8 days’)); To return weekly/total votes, you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)