WP_Query within function within WP_Query

Using wp_reset_query() really just makes sense if you are using query_posts(), which you don’t need and shouldn’t do – see When should you use WP_Query vs query_posts() vs get_posts()? . This means you should go with WP_Query and wp_reset_postdata() instead. Besides that you should give your custom, secondary queries a object, name differing from $query … Read more

Can’t get simple meta queries to work

It seems the ‘type’ => ‘string’ is not right From the codex type (string) – Custom field type. Possible values are ‘NUMERIC’, ‘BINARY’, ‘CHAR’, ‘DATE’, ‘DATETIME’, ‘DECIMAL’, ‘SIGNED’, ‘TIME’, ‘UNSIGNED’. Default value is ‘CHAR’. try and remove the above line from the code and check or try using the below instead. ‘type’ => ‘CHAR’

get_posts output always same post

This is because you are not passing the parameters in the correct way, taxonomy param needs to be passed under tax_query. Please replace the $args with the below:– $args = array( ‘posts_per_page’ => 4, ‘tax_query’ => array( array( ‘taxonomy’ => ‘tag’, ‘field’ => ‘slug’, ‘terms’ => ‘pp’ ) ) ); For more details check the … Read more

Get a list of posts by specific category

You can also use the following query for getting the results if you have author_id, post_status and cat_id with you. global $wpdb; $author_id = 1; $cat_id = 1; $post_status=”publish”; /* Post Titles */ $search_titles = $wpdb->get_col( “SELECT DISTINCT post_title FROM $wpdb->posts LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) … Read more

Does meta_value (array) work with ‘orderby’?

Researching more, I got it to work with the following code $post = array( ‘posts_per_page’ => 10, ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => ‘category-1’ ), ‘meta_query’ => array( array( ‘key’ => ‘custom-key’, ‘value’ => array(1,100), ‘compare’ => ‘BETWEEN’, ‘type’ => ‘NUMERIC’ ) ), ‘meta_key’ => ‘custom-key’, ‘orderby’ … Read more

Posts in loop all show the same author when there are many authors

You need to move the bulk of your code into the loop proper. This part: $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); $ids[]= $post->ID; endwhile; } When the_post() executes, it populates the $post global upon which a number of template functions depend. The problem is that you are running your … Read more