query_posts orderby multiple ways

First you need to use the WP_Query to get those posts. Then you can orderby using the following array. // The Query $args = array( ‘cat’ => $category->term_id, ‘posts_per_page’ => -1, ‘orderby’ => ‘meta_value’, ‘meta_key’ => ‘_bunyad_review_overall’, ‘paged’ => ( get_query_var(‘paged’) ? get_query_var(‘paged’) : 1 ), ); $the_query = new WP_Query( $args ); // Create … Read more

Custom post query error

get_posts() doesn’t accept posts as input, it only takes argument to query posts. So it’s useless and breaking step in your process. It should work if you throw get_posts() out. See Displaying Posts Using a Custom Select Query in Codex for extensive writeup on custom queries. PS your query is seriously insecure, you need to … Read more

Order for custom field after the loop

Regions and cities fit perfectly in the concept of taxonomy: a way to group things (i.e. posts). And not so much in the concept of meta data. I strongly recommend to use custom taxonomies for that instead of custom meta fields. You will gain in performance and you will have a better data relationship management. … Read more

Multiple posts/pages in one page?

More complex way I use it this way (I’m usually doing one page design, however the method of loading pages is still same). Fo Theme options, I’m using Option tree plugin where my clients could just checkbox which pages should appear there (it’s passed by it’s ID) and than I load it into the script. … Read more

Way to cache a query for 24 hrs

You can use WP_Object_Cache combined with a persistent cache plugin or you can use Transient API. WP_Object_Cache: // Random post link function randomPostlink(){ $cache = wp_cache_get( ‘random_tip_link’ ); if( $cache ) { echo $cache; } else { ob_start(); $RandPostQuery = new WP_Query(array(‘post_type’=>array(‘tip’),’posts_per_page’ => 1,’orderby’=>’rand’)); while ( $RandPostQuery->have_posts() ) { $RandPostQuery->the_post(); echo the_permalink(); } wp_reset_postdata(); $cache … Read more

How exclude 3 latest posts of a category in query_posts

I’d do it like this: $excluded_posts = array(); // select first 3 featured posts ordered by date $args = array ( ‘post_type’ => array( ‘post’ ), ‘category_name’ => ‘featured’, ‘posts_per_page’ => ‘3’, ‘order’ => ‘DESC’, ‘orderby’ => ‘date’, ‘ignore_sticky_posts’ => true, // or maybe not? ); $query = new WP_Query( $args ); while ( $query->have_posts() … Read more

WP-API: get posts in multiple categories

Assusming you are using V1 of the WP-API, did you tried the following endpoint: http://www.example.com/wp-json/posts?filter[category_name]=pink+warm I’m looking at the code in WP_JSON_Posts class and the get_post() should be able to handle that use case. UPDATE: It seems there is a limitation with the way the query is built. Here is a potential workaround: add_filter(‘json_query_var-category_name’, function( … Read more

How to reverse post navigation at bottom of post

You need to swap their arguments & rel tag too: <?php echo str_replace( ‘rel=”next”‘, ‘rel=”prev”‘, get_next_post_link( ‘%link’, _x( ‘<span class=”meta-nav”>&larr;</span> %title’, ‘Previous post link’, ‘twentythirteen’ ) ) ); ?> <?php echo str_replace( ‘rel=”prev”‘, ‘rel=”next”‘, get_previous_post_link( ‘%link’, _x( ‘%title <span class=”meta-nav”>&rarr;</span>’, ‘Next post link’, ‘twentythirteen’ ) ) ); ?>