Make query_post category name dynamic
Use get_the_title() replacing the_title(). Difference is get_the_title() returns the value while the_title() echos it.
Use get_the_title() replacing the_title(). Difference is get_the_title() returns the value while the_title() echos it.
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
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
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
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
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
Couple of things – avoid query_posts, use a new query object or the get_posts function (read all about it). And the_ID() echo’s the ID, use get_the_ID() instead. However, you can save some memory and processing by simply iterating over an array of posts (i.e. not using a proper “loop” and setting up the global post), … Read more
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
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
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”>←</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”>→</span>’, ‘Next post link’, ‘twentythirteen’ ) ) ); ?>