Next/Prev posts on same page

Pass Paged into parameter array of query_posts You should set get_query_var( ‘paged’ ); if you want your query to work with pagination. $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args_news= array( ‘cat’ => 1, ‘posts_per_page’ => 2, ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, ‘numberposts’ => -1, ‘paged’ => $paged, ); query_posts( $args_news ); if ( … Read more

How use %like% in sql statement wordpress

$wpdb->prepare() doesn’t actually fully support sprintf() placeholders. From the Codex: The query parameter for prepare accepts sprintf()-like placeholders. The %s (string), %d (integer) and %f (float) formats are supported. It’s not entirely obvious from that but the argument swapping formats (e.g. %1$d) are not supported (in any case you have the incorrect syntax: it should … Read more

Meta Query for specific months

You need the 2 digit month number that you want to query on and then use the code below. This should be easy with php (for example, see this post). In the code below $month is the number of the month in a 2 digit format, eg March would be 03. $start_date = date(‘Y’.$month.’01’); // … Read more

Custom Query – show first post twice?

Just rewind posts after the first post and run the loop again. if($test->have_posts()) : $test->the_post(); the_title(); endif; $test->rewind_posts(); if($test->have_posts()) : while($test->have_posts()) : $test->the_post(); the_title(); endwhile; endif;

WP_query Date Range results not matching loop

Try to run your query with “suppress_filters” => true WP_Query allows for posts to be added after the query has run. found_posts is the actual queried amount of posts, post_count is updated after running the filters. If this fixes it search your code (Any active code, check network activated plugins as well) for the_posts or … Read more

How to prevent writing duplicate loops?

Move the control structure outside the template file and just put the repeatable markup and template tags inside. $event_query = new WP_query($args); if( $event_query->have_posts() ){ while( $event_query->have_posts() ){ $event_query->the_post(); get_template_part(‘loop’, ‘home’); } } wp_reset_postdata();

Display posts if specific country

Take a look at freegeoip.net. I used it like this with jquery, for example. $.get( “http://freegeoip.net/json/”, ‘jsonp’, function( data ) { country = data[‘country_code’]; if( country == ‘US’ ){ // show your content }; });