SQL Query inside Widget

“SELECT name FROM wp_venues WHERE name=””.the_field(“venue’).”‘ “; will only return the value of the_field(‘venue’) which is already known. “SELECT * FROM wp_venues WHERE name=””.the_field(“venue’).”‘ “; will select the whole row with all fields. Try too use $wpdb->prepare for security reasons. With $wpdb->get_row you get the whole row as either an object, a numerically indexed array … Read more

How to run WP_Query to retrieve attachments to posts only from a particular category?

You’ll need to first grab the posts, then grab the attachments that are children of said posts. $my_query = new WP_Query( array( ‘meta_key’ => ‘my_hash’, ‘nopaging’ => true, ‘orderby’ => ‘meta_value’, ‘fields’ => ‘ids’, ‘cat’ => ’60’, )); if ( $post_ids = $my_query->get_posts() ) { $post_ids = implode( ‘,’, $post_ids ); $atts_ids = $wpdb->get_col( “SELECT … Read more

WP_Query not retrieving by random order under parent

Turns out the “Custom Page Order” plugin was causing the randomization error… or rather, not allowing any randomization as it overrides it completely. Disabled the plug-in. Whenever I need to change orders, I can enable the plugin, shuffle pages around, and then disable. But the need for this is decreasing more and more as we … Read more

Count total number of post in foreach loop

Edit: Re-reading your question I noticed I may have mixed some things up, but the point remains that you should combine these separate queries performed inside the loop, by using variables inside the loop to create a comprehensive list of the query arguments that you can use to perform one query outside the loop. I’ve … Read more