wpdb update multiple row?

Your code of wpdb method is correct. posible reasons why it fails… you have only one user that match’s meta_key = ‘user_token’ other functionality change query at query hook filter strage. debug the final SQL with add_filter( ‘query’, ‘query_report’, 10000 ); function query_report($sql){ var_dump($sql); return $sql; }

Help with Related Posts Function

You can use WordPress’s tax_query arg when fetching posts to achieve what you’re trying to do, this is also easily extendable with more than one taxonomy. $query = array( ‘post_type’ => $YOUR_POST_TYPE, ‘posts_per_page’ => -1 // get all ‘tax_query’ => array( ‘relation’ => ‘OR’ ) ); $query[‘tax_query’][] = array( ‘taxonomy’ => ‘YOUR_TAXONOMY’, ‘terms’ => $ARRAY_WITH_TERMS, … Read more

How to create an overview of posts with the same tag?

foreach( $posts_array as $post ) { echo the_title(); } I think the problem is you call the_title() without setup_postdata first If I were you, I’ll simply use $post->post_title. foreach( $posts_array as $post ) { echo $post->post_title; } This is because you are “get_posts”ing within a loop, and setup_postdata will change global variable $post which is … Read more

Select min/max meta from query

You need subqueries. This is really a SQL question but as I know no way to do this with native WordPress functions without looping and running multiple queries here you go. $querystr = ” SELECT DISTINCT {$wpdb->posts}.ID, {$wpdb->posts}.*, (SELECT min(cast(meta_value as unsigned)) FROM {$wpdb->postmeta} WHERE meta_key=’_wp_price’ AND meta_value IS NOT NULL AND meta_value <> 0 … Read more

WordPress Mysql query and Duplicate

There’s no need for custom SQL here, use the power of meta queries: $posts = get_posts( array( ‘posts_per_page’ => -1, ‘meta_query’ => array( array( ‘key’ => ‘Country’, ‘value’ => ‘UK’, ), ), ) ); foreach ( $posts as $post ) $cities[] = get_post_meta( $post->ID, ‘city’, true ); foreach ( array_unique( $cities ) as $city ) … Read more

how do i register global query in template

Declare an array at the start of your layout, or in your functions file depending on the scope required and populate the array with all the bands using get_posts and making the key the post ID. You will then have a global array of bands, and can pull info from each one wherever you need … Read more

How to rearrange a pool of posts joined using two queries?

This is how I would approach it: Code function my_pseudo_date_query( $where, $query ) { global $wpdb; $dq = $query->get(‘my_date_query’); if( $dq && !empty( $dq[‘after’] ) ){ $where .= $wpdb->prepare( ” AND {$wpdb->posts}.post_date >= %s” $dq[‘after’] ); } if( $dq && !empty( $dq[‘before’] ) ){ $where .= $wpdb->prepare( ” AND {$wpdb->posts}.post_date <= %s”, $dq[‘before’] ); } … Read more

Select column name dynamically mySQL Query

I guess one could argue that this is somewhat wordpress related, because you are trying to get_results() from $wpdb, but like @MarkKaplun said your problem is that you are using the SQL wrong. Below code is an example on how to do it correct: $dr = $wpdb->get_results( $wpdb->prepare( “SELECT * FROM wp_shipping WHERE country = … Read more

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