Alter post order on taxonomy template

I’ve assumed that since the posts have already been returned then I should use ‘query_posts’ to alter the order of the posts. That assumption is wrong. You should pretty much never use query_posts. Use a filter on pre_get_posts. function pregp_wpse_108235( $qry ) { if ( $qry->is_main_query() && $qry->is_tax() ) { $qry->set( ‘order’, ‘ASC’ ); } … Read more

Checking for two categories in query_posts

Don’t use query_posts. Use WP_Query, and use it’s tax_query. $query = new WP_Query( array( … ‘tax_query’ => array( array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => array( ‘recent-work’, ‘plumbing’, ‘cat3’ ) ) ), ‘posts_per_page’ => 1 … );

Co-authors plus problems with query_post

Please don’t use query_posts. Just don’t. Create a new query with WP_Query. Secondly, I am not sure how you are trying to use multiple authors in the query but I assume you are using author and a comma separated string of IDs or author__in and an array. For example: $query = new WP_Query( ‘author=2,6,17,38’ ); … Read more

How To Get Posts With A Specific Word

What you’ve described is just a search for the words “Dolph Ziggler”. You can use WP_Query as such $query = new WP_Query( ‘s=keyword’ ); Note, that you’ll probably want to cache those queries as they’ll be very slow.

Inserting custom data to the_post() during loop

Yep, it’s not very common, but perfectly viable and nifty technique. After the posts are retrieved in WP_Query they are passed through the_posts filter like this (where $this is WP_Query instance): $this->posts = apply_filters_ref_array( ‘the_posts’, array( $this->posts, &$this ) ); You just loop through array and assign the extra data you need to objects. Don’t … Read more

Order posts by condition

As Tom said, you should never use query_posts and should almost always pass any arguments as an array. I think this will achieve what you want: <?php // Arguments $args = array(‘ ‘nopaging’ => true, ‘terms’ => ‘featured’, ‘posts_per_page’ => 15, ‘orderby’ => ‘rand’, ‘order’ => ‘DESC’, ‘); // The query $the_query = new WP_Query( … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)