How can I change my meta_query to SQL wpdb query?

Several things, Firstly you can add the following for pagination: ‘paged’ => ( get_query_var(‘paged’) ? get_query_var(‘paged’) : 1 ) This removes the need for the array_merge. Otherwise your existing code is fine except for some indentation. I would add the rest of the query though, e.g. defining the post type, the posts per page, etc

$wpdb->get_var next var?

Instead of querying the database directly you could use the following code instead. printf( ‘<p>Total views : %s</p>’, get_post_meta( get_the_ID(), ‘views’, true ) );

$wpdb->num_rows doesn’t work

A few things I would do/add/change: Instead of using a query function directly I would use $wpdb->get_results Second, $wpdb->num_rows will work now. Third: setup_postdata() is what you need to actually make use of the query outside of a loop. This means get_post(get_the_ID()) doesn’t apply to anything as there is no existing $post-ID to reference. I … Read more

$wpdb->prepare error after WordPress update [duplicate]

Because you’re missing second argument, for more information see this post – http://make.wordpress.org/core/2012/12/12/php-warning-missing-argument-2-for-wpdb-prepare/. Also you’re doing it wrong, for security reason you shouldn’t pass variables into query directly that’s why you should use prepare() method – see Codex for usage info.

WPDB Query Question with Category Only

This is a SQL problem. Your query is wrong. You forgot to include the term_relationships table in the query, yet reference it during the JOIN. By including the term_relationships table, that would solve the problem with the query. SELECT ID, post_title, post_content, post_date FROM {$wpdb->posts} AS p JOIN {$wpdb->term_relationships} AS tr ON tr.object_id = p.id … Read more

Get all sticky posts from one user through user ID

Copy and paste this function into the function.php file under current theme. // Create a new filtering function that will add where clause to the query function filter_where( $where=”” ) { // posts in the last 30 days $where .= ” AND post_date > ‘” . date(‘Y-m-d’, strtotime(‘-30 days’)) . “‘”; return $where; } Paste … Read more

query a newly created table using $wpdb

you doing something wrong your $result query returns multidimensional array of rows and each row has an array of keys values, try this, not tested but will work. <?php global $wpdb; $result = $wpdb->get_results ( “SELECT * FROM $wpdb->forms” ); foreach ( $result as $key => $row ) { echo $row->ID.'<br/>’; } ?>

Can I use wpdb to insert query results into a post?

$wpdb is a relatively simple wrapper around PHP’s mysql functions. If you can do it with PHP/SQL then you can do it with $wpdb. You’re question is not detailed or specific enough to afford a more detailed answer though. Nor is it detailed enough to say whether $wpdb is the best, or even an acceptable` … Read more

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