Getting additional columns from sql

You need to add another join: INNER JOIN $wpdb->postmeta rate_review ON p.ID = rate_review.post_id Add the condition to your where clause: AND rate_review.meta_key = ‘rate_review’ Now you can add it to your SELECT: rate_review.meta_value AS rate_review

Get multiple users with meta value in one query and populate WP_User class

For anyone interested. Got it solved using the get_user_metadata filter to short circuit the metaquery and cache loading. Steps: Run query Store result data in the class property Add get_user_metadata filter Start foreach loop on results Trigger new WP_User( $result_value ) for each result Within the filter function, validate meta key on $wpdb->get_blog_prefix() . ‘capabilities’. … Read more

Query posts that contain video?

I don’t think there’s a fool-proofed way to do that, because the YouTube videos can be embedded in various ways and later be removed from the posts’ content. Here are few ideas: If you mean searching for e.g. the youtube string, then you could use the s argument in WP_Query. But the links might be … Read more

post_type argument not working correctly with WP_Query

Your $args array should not have the call to get_posts(). $args should just be an array: $args = array( ‘numberposts’ => -1, ‘post_type’ => ‘page’, ‘meta_key’ => ‘top-story’, // true-false ‘meta_value’ => ‘1’ ); $the_query = new WP_Query($args);

Changing the default wp_search_stopwords

You are close: you indeed need to define a filter, but you’ve not quite gotten the filter definition right: function add_meh_stopword($stopwords) { $stopwords[] = ‘meh’; // *add* “meh” to the list of stopwords // if instead you want to completely replace the list of stopwords // use $stopwords = array(‘meh’); return $stopwords; } add_filter( ‘wp_search_stopwords’, … Read more

How to retrieve the data from the sever and displaying it in a page?

So in this case, the problem is that your line right before the echo call is incomplete: $number_rows= $wpdb->get_var( “SELECT COUNT(*) FROM $wpdb->daviddgl_wp1.SaveContactForm7_7” ); $x=1; while ($x<$number_rows) { $results = $wpdb->get_results(“SELECT ticket, name,email FROM $wpdb->daviddgl_wp1.SaveContactForm7_7 WHERE id = $x”); print_r($results); $x++; } (You’re missing the closing bracket and semi-column) Note also that your echo will … Read more

Co-authors list of all posts

Nevermind, I fixed it by changing query by author_name instead of ID Works! $the_query = new WP_Query( array( ‘posts_per_page’ => -1, ‘author_name’ => get_the_author_meta(‘nickname’), ) ); We can close this question!

Exclude parent with child pages from WP_Query

the_dramatist’s answer will give you only top-level pages that have no children, which matches the example given in your description. However, if you want to get ALL leaf pages, use the following: SELECT * FROM $wpdb->posts WHERE post_type=”page” AND ID NOT in ( SELECT ID FROM $wpdb->posts WHERE post_type=”page” AND ID in ( SELECT post_parent … Read more