Select User by Joining Multiple Meta Value Results

Try this one with additional join on metadata SELECT u.ID, u.display_name FROM wp_users u LEFT JOIN wp_usermeta um1 ON u.ID = um1.user_id LEFT JOIN wp_usermeta um2 ON u.ID = um2.user_id WHERE um1.meta_value=”value1″ AND um1.meta_key = ‘key1’ AND um2.meta_key = ‘keyA’ AND um2.meta_value=”valueA” GROUP BY u.ID Also use group by

Query posts by content lenght

I want to suggest you another approach. You can set a meta when you saving a post if its content is less than 140 chars, so then you can simply runs a simple meta query. add_action( ‘save_post_post’, function( $id, $post ) { if ( $post->post_status !== ‘publish’ ) { return; } if ( strlen( $post->post_content … Read more

How many queries are normal to execute on a WP site?

I wouldn’t say it’s not “normal”, but it’s above typical. The common minimum of queries would go like: main query (set of posts) functionality (menus, widgets, etc) data (terms and such) On a WP test data that would make something under 50 queries on home page. With object cache it will fall under 10 on … Read more

Two differents queries in archive page

You’ve added the filter lm_exclude_bio to pre_get_posts. So when you need to run another query you can remove the filter to get normal query. You can remove the filter like below- // Here we’re removing the filter first. Then we are running the query. remove_filter( ‘pre_get_posts’, ‘lm_exclude_bio’ ); $args = array( ‘post_type’ => ‘bio’, ‘posts_per_page’ … Read more

WordPress Find Duplicate Post By Content

Try to use the following SQL query to fetch duplicate posts: SELECT p2.* FROM wp_posts AS p1 LEFT JOIN wp_posts AS p2 ON p1.post_content = p2.post_content AND p2.ID < p1.ID AND p1.post_type = p2.post_type AND p1.post_status = p2.post_status WHERE p1.post_type=”post” AND p2.ID IS NOT NULL

How can I apply a meta query for a single custom post type in the main query?

In the case that the start_date custom field only exists for the event post type, this works: $query->set( ‘meta_query’, array( ‘relation’ => ‘OR’, array( ‘key’ => ‘start_date’, ‘compare’ => ‘NOT EXISTS’, ), array( ‘key’ => ‘start_date’, ‘value’ => $today = date( ‘Ymd’ ), ‘compare’ => ‘>=’, ), array( ‘key’ => ‘end_date’, ‘value’ => $today = … Read more

wpdb::prepare() isn’t working

The issue is that in My/SQL table names are not strings. So ‘wp_product_codes’ is being interpreted as a string instead of as an actual table. This is why you usually don’t see tables passed into wpdb::prepare() – you should know the table names as they won’t change where wpdb::prepare() is meant for data that you … Read more

Is there a conditional tag for latest post or do i need a query?

Within an ordinary WordPress Loop, the following would identify the first post in the Loop, which would be the latest if posts are ordered by date descending. global $wp_query; // might not be necessary; depends on context if (is_paged() && 0 === $wp_query->current_post) { echo ‘first-post’; } I don’t know how your custom function works … Read more

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