Display posts with date wordpress default

you need to study about date query. Anyways following should work <?php $args = array( ‘posts_per_page’ => -1, ‘date_query’ => array( array( ‘after’ => ‘7 days ago’ ) ) ); $query = new WP_Query($args); while ( $query->have_posts() ) { $query->the_post(); // Page title the_title(); } // end while // Restore original Post Data wp_reset_postdata(); // … Read more

Meta query with JSON value

That’s not json. You can’t put a semi-colon inside a javaScript Object like that. That’s serialized-data. If you return that string & then call unserialize on it & then var_dump you can see what’s inside. Also, see fuxia♦’s Answer Here for more info. & to Maikal’s credit, you can use a meta_query in this situation, … 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

WP_Query times out

What you are seeing isn’t “bad” exactly, you’ve just got a terrifically labor intensive query and WP_Query is not smart enough to optimize it– it doesn’t even try. Briefly, you’ve got a bunch of JOINs, you’ve got two LIKE conditions, which will read every row in the table of that post type, those likes are … 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

WP_Query arguments to fetch custom post type posts which are in certain category?

If you want your main query to take in account your custom post type, you can do as shown below : function add_custom_post_type_to_query( $query ) { if ( $query->is_archive() && $query->is_main_query() ) { $query->set( ‘post_type’, array(‘post’, ‘my_custom_post_type’) ); } } add_action( ‘pre_get_posts’, ‘add_custom_post_type_to_query’ ); You can place the above code in your theme’s functions.php or … Read more