$wpdb doesn’t appear to work on page inside of a plugin

The $wpdb object is part of WordPress, so wouldn’t be loaded into a standalone PHP page as it is into a WordPress template. You might want to look into creating your own page templates, then you could run your database query as part of that page template. As a side note: You are currently trusting … Read more

How do I find if a page has a template?

This should do the trick for you. This shows what template file is stored in post_meta, if one has been selected in the admin panel: $template_name = get_post_meta( $the_query->post->ID, ‘_wp_page_template’, true ); If you want to see if the page is the homepage, use is_home() or is_front_page(). If you want to see what files are … Read more

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