WP Query group/order by category name

There are a few ways you can do this. The simplest is to just get everything: posts and terms, then use some array_filter magic to group things. Simple example (that will only work with PHP 5.3+): <?php $terms = get_terms(‘your_taxonomy’); $term_ids = array_map(function($t) { return $t->term_id, }, $terms); $posts = get_posts(array( ‘nopaging’ => true, ‘tax_query’ … Read more

Include both default and Custom Post Type in query modified inside pre_get_posts

As Kaiser mentioned, the post_type parameter can accept an array of post types. Updating the function to use is_main_query() to limit the filter to only the “main” query, the code would look like: add_action( ‘pre_get_posts’, ‘custom_post_author_archive’ ); function custom_post_author_archive( $query ) { if ( is_main_query() && is_author() ) { set_query_var( ‘post_type’, array(‘post’,’custom_post’) ); } }

wp query by search in titles only & put the posts in loop

If you want to limit the filter from this answer (add that function to your plugin or your theme’s functions.php) just to one query, remove the filter when you are done: add_filter( ‘posts_search’, ‘__search_by_title_only’, 500, 2 ); $query = new WP_Query( array( ‘s’ => ‘mykeyword myotherkeyword’, ‘cat’ => array( 22, 32 ), ‘orders’ => ‘DESC’, … Read more

Query not returning CPT posts

I had a similar problem and posted the solution here: http://wordpress.org/support/topic/role-scoper-updating-query_posts query_posts causes the main WP_Query to be discarded. That may or may not be the behavior you want. If no, you need to update WP_Query, then you could update your functions.php file to include a register filter that displays your content types as part … Read more