query posts in wordpress

There is no term_id parameter. You need a tax_query. $args = array( ‘post_type’ => ‘my_post’, ‘posts_per_page’ => 6, ‘tax_query’ => array( array( ‘taxonomy’ => ‘yourtaxname’, ‘field’ => ‘id’, ‘terms’ => 1 ) ) ); $query = new WP_Query( $args ); Notice that I’ve use new WP_Query and not query_posts. Don’t use query_posts. Doing the above … Read more

Can not switch the queried post in pre_get_posts hook

Huh. I double-checked. On my local server, this bit of code successfully changes the post: function test_redirect() { global $wp_query; $wp_query->set(‘page_id’, 5); } add_action(‘pre_get_posts’, ‘test_redirect’); You’re going to have to do a bit of debugging. On a dev server, var_dump the $wp_query variable a few key places to check that it has what you expect … Read more

cloning a WP_Query

You shouldn’t have to “get your query back”. Your queries are all stored in different objects– $team, $reports_played, the original $wp_query, etc. Just access the particular object that you need to use. This is untested but to get functions like the_title working, run $query_object_name->the_post() at the top of each Loop iteration and $post = $parent_object_name->post … Read more

How to Check if a Child Category is Being Queried

The function cat_is_ancestor_of takes two arguments (two category IDs). To check if category of ID 61 is ancestor of category with 54: cat_is_ancestor_of(54,61); I’m not sure if there is a better way of doing this, but you can get the current category’s ID with the get_queried_object() and then check this an ancestor of the category … Read more

WP-PageNavi gives me a 404 when using WP Query

This could be a plugin compatibility problem. Have you tried to disable all plugins and see if that solves the problem? I found this which may also be of help: http://dre.im/if-pages-return-a-404-after-wordpress-3-1-upgrade/ Log in to wp-admin and go to permalinks, click save (this should refresh your permalinks). Check to see if this fixes your permalinks. If … Read more

If orderby parameter using pre_get_posts is the same for multiple posts what fallback does the query use?

For identical values they’ll be in whatever order they’re returned by the database engine, which would typically be the order they were inserted in the database. Anyway, the question you’ve linked is old, you can order by multiple columns with WP_Query: $query->set( ‘orderby’, array( ‘menu_order’ => ‘ASC’, ‘date’ => ‘ASC’ ) ); pre_get_posts acts on … Read more