Filtering The Loop For Single Page and Blog Page

As an example (adjust to suit your needs): add_action(‘loop_start’, function() { if ( is_single() || is_home() ) echo ‘<div>’; }); add_action(‘loop_end’, function() { if ( is_single() || is_home() ) echo ‘</div>’; }); You may need to adjust the conditional statements further if you wish to target archive pages and the like — learn more about … Read more

Get Pagination (WP-PageNavi) not to work

Couple of issues here; Don’t use get_posts for paginated queries. It legally breaks/ignore pagination as it passes no_found_rows=true to WP_Query. Further more, get_posts only returns the $posts property from the query object, and pagination needs other properties from the query object to calculate pagination. You can paginate get_posts, but it is a really messy affair, … Read more

ACF – Get lowest & highest value from field

Got it working in the end with the below code: <?php $args = array( ‘posts_per_page’=> -1, ‘post_type’ => ‘properties’, ‘meta_key’ => ‘development’, ‘meta_value’ => $development_id, ); $properties_query = new WP_Query( $args ); $prices = array(); if( $properties_query->have_posts() ): while( $properties_query->have_posts() ) : $properties_query->the_post(); $price = get_field(‘price’); if(isset($price) && !empty($price)){ $prices[] = $price; } endwhile; $max_price … Read more

Must Use Plugin Causing Query Error

As Milo ( and your errors ) point out: you’re passing an array where a string is expected. According to WP_Query tag parameter Show posts associated with certain tags. tag (string) – use tag slug. To get around this you just need to pass a comma separated string: function custom_tags( $query ) { $query->set( ‘tag’, … Read more

WP_Query loop within WP_Query loop

It is still totally unclear what you actually want to do, but according to this: it works but the main loop generate duplicate posts I can tell you that it is expected output. Your “main” loop queries and displays all pages which has a parent page ID of 10. Lets say there are 10 pages … Read more

How to limit WP_Query to one result on the loop?

pre_get_posts alters all queries, back end and front end regardless. There are two very important checks that a large amount of people misses, that is the !is_admin() check which only targets the front end, and then the most important check, is_main_query() which will only alter the main query and not custom queries. You statement should … Read more

spliting posts into two columns

You could always try to create 2 arrays of titles, say $left and $right, $odd and $even, or $tom and $jerry, and fill them with the titles during your loop, and print them after the loop has ended like so: Create array $left = $right = array(); Then unleash your loop [edited the below to … Read more

Get posts for last working week in WP_Query

Well, try the below code- $base_array = array( ‘posts_per_page’ => -1, ‘fields’ => ‘ids’, ‘post_type’ => ‘cpt’, ‘post_status’ => array(‘publish’), ‘date_query’ => array( ‘after’ => strtotime( ‘previous week Monday’ ), ‘before’ => strtotime( ‘previous week Friday’ ) ) ); $base = get_posts($base_array); I’ve not tested it. But I tested that below code returns the perfect … Read more