tax_query in get_posts() not working?

tax_query takes an array of tax query arguments arrays (it takes an array of arrays) but you are using only single array. The correct code is as following. $uposts = get_posts( array( ‘post_type’ => ‘product’, ‘numberposts’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => $cat->taxonomy, ‘field’ => ‘slug’, ‘terms’ => array($cat->slug), ‘operator’ => ‘IN’, ) … Read more

WP_Query vs get_posts

The difference between get_posts & WP_Query You can view get_posts() as a slimmed down WP_Query. In fact looking at the source: //… prepares query array $r $get_posts = new WP_Query; return $get_posts->query($r); get_posts() use WP_Query, but only returns an array of posts – nothing more. Furthermore it sets: $r[‘no_found_rows’] = true; Normally (by default with … Read more

How to use the_posts_navigation for wp_query and get_posts?

the_posts_navigation() is simply a wrapper function for get_the_posts_navigation() which issimply a wrapper function for paginate_links. The first two functions uses the the same exact parameters that is being used by paginate_links and actually passes it to the latter function as well get_the_posts_navigation() and the_posts_navigation() is good new functions as it eliminates a lot of custom … Read more

How to get all children and grandchildren of a hierarchical custom post type?

You will need to loop over those posts and then do more queries for each post, repeating until you find no posts in a query. e.g. function get_posts_children($parent_id){ $children = array(); // grab the posts children $posts = get_posts( array( ‘numberposts’ => -1, ‘post_status’ => ‘publish’, ‘post_type’ => ‘microsite’, ‘post_parent’ => $parent_id, ‘suppress_filters’ => false … Read more

Query Posts or Get Posts by custom fields, possible?

To query posts by custom fields you can use the ‘meta_query’ parameter <?php $args = array( ‘post_type’ => ‘payment’, ‘meta_query’ => array( array( ‘key’ => ‘bookingref’, ‘value’ => ‘the_value_you_want’, ‘compare’ => ‘LIKE’ ), array( ‘key’ => ‘customerref’, ‘value’ => ‘the_value_you_want’, ‘compare’ => ‘LIKE’ ) ); query_posts($args); while (have_posts()) : the_post(); ?> you can’t use get_post_meta … Read more

get_post random and order by not working

Yes, this is the correct syntax: $args = array( ‘orderby’ => ‘rand’, ‘order’ => ‘ASC’ ); query_posts( $args ); However plugins can keep this from working properly. Try disabling ALL plugins and see if that helps. Two known plugins which keep orderby=rand from working are Post Type Order and WP_Sticky Also, if you have Post … Read more

How to show related posts by category

The question has already been asked and the answer has been posted too, How to display related posts from same category? Add this code inside your single.php after a loop wherever you want to show related post, <?php $related = get_posts( array( ‘category__in’ => wp_get_post_categories($post->ID), ‘numberposts’ => 5, ‘post__not_in’ => array($post->ID) ) ); if( $related … Read more

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