Help with a query not working with custom taxonomy

Try something like this: $sotmArticle_query = new WP_Query( array( ‘post_type’ => ‘news’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘postCat’, ‘field’ => ‘slug’, ‘terms’ => ‘sotm’ ) ), ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘posts_per_page’ => 1 ) ); if($sotmArticle_query->have_posts()){ while($sotmArticle_query->have_posts()){ $sotmArticle_query->the_post(); ?>

Using next/previous_posts_link with customised search

You don’t need the type variable and other bits of custom search query code, or custom functions like the other answers. In your searchbox, instead of submitting the form to / submit it to /my_post_type/ instead! WordPress will handle all the rest for you automagically, with no effort involved. What’s more this means all the … Read more

Trying to list out child pages with WP_Query

I tested the query and it does work so the only thing I can spot that is misleading but not right is directly after you while() statement you have the_post(). This doesn’t work in secondary queries, it should look like: <?php if( $subpages->have_posts() ) : ?> <?php while( $subpages->have_posts() ) : $subpages->the_post(); ?> … <?php … Read more

WP_Query post at custom position

Pagination should be easy. You really just need to add pagination parameters to your query, and next/previous posts links, more or less like in another thread I posted in recently. $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $my_query = new WP_Query( array( ‘showposts’=>10, ‘paged’ => $paged ) ); // run the loop then, // pagination … Read more

WP_Query multiple use of relation and/or

No, meta_query does not support these sorts of complex clauses in a sequence. There are a couple of ways to work around this limitation. One is to filter posts_where_paged and modify the SQL manually. I just spent a couple minutes playing with this option, and it’s not very straightforward – you’ll have to write a … Read more

Sort posts by activity date

I like the idea proposed in this comment. Connecting the posts table to the comments table seems like it’d be some super complicated SQL (well all SQL is complicated to me). Instead the link proposes that you add a post meta field to the post to hold the date of the most recent comment. add_action(‘comment_unapproved_to_approved’, … Read more