meta_query with multiple values optimization

Post meta data was never designed to be used efficiently in queries. Using it with LIKE based matching will only make it more horrible. You need to rethink your DB. For example use taxonomy terms to indicate which social network is associated with a post.

How to query wp_postmeta table for any specific meta_value?

$wpdb->wp_postmeta is wrong. Always use just $wpdb->postmeta – without further prefixes. So… global $wpdb; $querystr = ” SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key LIKE ‘movie_name’ ORDER BY meta_value ASC “; $movie_names = $wpdb->get_results( $querystr, OBJECT ); if ( ! $movie_names ) { $wpdb->print_error(); // Get the last error message for debugging } else { … Read more

pre_get_posts and set

pre_get_posts triggers for every query (front and admin side). It also triggers when querying nav-menu items (which is what is happening here). Most of the time you only want to filter particular queries – so you need to check if that query is one you wish to modify. Usually – and I think your example … Read more

Meta query – How to display a null meta key

Finally, this meta_query works : ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘votes_average’, ‘value’ => ‘6’, ‘compare’ => ‘<‘, ‘type’ => ‘NUMERIC’, ), array( ‘key’ => ‘votes_average’, ‘compare’ => ‘NOT EXISTS’, ‘value’ => ‘null’, ) ),

Filter posts by meta query?

It is a little more convoluted, but main queries for admin can be modified roughly in a same way as front end. You would need to: hook into pre_get_posts check for is_admin() check for is_main_query() check for specific page you want to adjust apply your adjustments to the query if all matches

Wp Query custom search by meta query

I did it this way: $name = explode(‘ ‘, $name); foreach($name as $string) { $args[‘meta_query’][] = array( ‘key’ => ‘name’, ‘value’ => $string, ‘compare’ => ‘LIKE’ ); } Which works good, but I’m not sure if that’s the best solution.

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