Mysql query LIKE not working

Prepare your Queries! global $wpdb; $wpdb->get_results( $wpdb->prepare( “SELECT %s blog_id, last_updated FROM %s WHERE public=”1″ AND archived = ‘0’ AND mature=”0” AND spam = ‘0’ AND deleted =’0′ AND UPPER(blog_name) LIKE ‘%s’ %s %s “, ARRAY_A ), $extra, $wpdb->blogs, $wpdb->esc_like( ‘A%’ ), $order, $limit ); Never ever send data without prepare! Also: There’re some functions … Read more

Is it possible to create a shortcode that will query a post based on taxonomies?

here is a simple shortcode that can handle taxonomies, post types and any other parameter that WP_Query takes: add_shortcode(‘posts’,’posts_shortcode_handler’); function posts_shortcode_handler($atts, $content){ extract(shortcode_atts(array( ‘posts_per_page’ => ‘5’, ), $atts)); global $post; $temp = $post; $posts = new WP_Query($atts); $retVal=””; if ($posts->have_posts()){ while ($posts->have_posts()){ $posts->the_post(); // these arguments will be available from inside $content $parameters = array( … Read more

Multiple post type queries (with specific arguments for each)

Could you do something like this? <?php $args = array( ‘post_type’ => array(‘post’,’movie’,’actor’), ‘posts_per_page’ => ’20’, ); query_posts( $args ); while ( have_posts() ) : the_post(); global $post; if (($post_type == ‘movie’) && (get_post_meta($post->ID, ‘meta_key’, true) == ‘your-value’)) { // Display your content for Movie Post Type with meta value set } else if (($post_type … Read more

Conditional arguments WP_Query for post custom fields

Here is a modification of your code where you can add the meta query if certain $GET keys are set. $query_array = array(‘relation’ => ‘AND’); if(isset($_GET[‘gender’]) && !empty($_GET[‘gender’])){ $gender = $_GET[‘gender’]; array_push($query_array, array(‘key’ => ‘wpcf-gender’, ‘value’ => $gender, ‘compare’ => ‘=’)); } if(isset($_GET[‘city’]) && !empty($_GET[‘city’])){ $city = $_GET[‘city’]; array_push($query_array, array(‘key’ => ‘wpcf-city’, ‘value’ => $city, … Read more

How can I query posts with newly uploaded images?

This should do it for you. If you’re calling it in a function, you’ll of course need to ensure $wpdb is the global. $required_number_of_attatchments = 3; $posts = $wpdb->get_col( $wpdb->prepare( “SELECT posts.ID FROM %s AS posts INNER JOIN ( SELECT MAX(post_modified) AS modified, post_parent FROM %s WHERE post_type=”attachment” AND post_parent > 0 GROUP BY post_parent … Read more

How can i simulate “taxonomy__in” in query?

You can’t, because of the way categories and general taxonomies operate. Categories are a type of taxonomy, so we are querying one level lower when querying for categories. When you query for category__in => array() it actually looks up what category_terms are queried and queries posts from all those categories. Now this effect we can … Read more

How to apply filter inside a single wp_query?

You should consider using the posts_per_page parameter as suggested by @Tamil. But in general you can also remove the filters you add. In your case you could remove it after your WP_Query() with add_filter( ‘post_limits’, ‘my_post_limits’ ); $slider_query = new WP_Query( $args ) remove_filter( ‘post_limits’, ‘my_post_limits’ ); so it won’t affect later queries. You can … Read more