Adjust the order for returned posts

In order to accomplish what you desire, you’ll have to fetch the posts ahead of time. There is no way to specify in SQL an arbitrary ordering given an ID list. query_posts() creates another main query, throwing out the main query. Since you’re doing this anyway, you can use get_posts() to return a list of … Read more

WP_Query () using taxonomy, custom post types

<?php $args = array( ‘post_type’ => ‘care-agency’, ‘meta_key’ => ‘wpcf-listtype’, ‘meta_value’ => ‘Enhanced Listing’ ); $loop = new WP_Query( $args); if ( $loop->have_posts() ) { while ( $loop->have_posts() ) : $loop->the_post(); //Here goes my loopy stuff endwhile; } All taken from the codex on WP_Query.

Exclude posts based on an array

You’re looking for post__in & post__not_in parameters http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters Both of them are an array of ID’s for the post’s to include or exclude in the results BTW in your code, you had a semicolon just after your foreach

wpdb update multiple row?

Your code of wpdb method is correct. posible reasons why it fails… you have only one user that match’s meta_key = ‘user_token’ other functionality change query at query hook filter strage. debug the final SQL with add_filter( ‘query’, ‘query_report’, 10000 ); function query_report($sql){ var_dump($sql); return $sql; }

Get 1st parent category id from post

You need to use get_ancestors(). Assuming your post is only in one category, the following code should work (if it’s in multiple you’ll need to loop through each of the assigned categories to determine the various hierarchies). $category = get_the_category(); $ancestors = get_ancestors( $category[0]->term_id, ‘category’ ); $direct_parent_id = $ancestors[0]; If you want to get the … Read more

Help with Related Posts Function

You can use WordPress’s tax_query arg when fetching posts to achieve what you’re trying to do, this is also easily extendable with more than one taxonomy. $query = array( ‘post_type’ => $YOUR_POST_TYPE, ‘posts_per_page’ => -1 // get all ‘tax_query’ => array( ‘relation’ => ‘OR’ ) ); $query[‘tax_query’][] = array( ‘taxonomy’ => ‘YOUR_TAXONOMY’, ‘terms’ => $ARRAY_WITH_TERMS, … Read more