I am building a meta query array and all fields for the user are optional so some might not have any data. But there is also an option which requires a date query. I am still checking to see if this is working but not sure as of yet. Is this correct and if not, what would be the right way to do it? Not sure if there needs to be an OR condition in here somewhere. $meta_query = []; …
I am trying to use get_posts to return data between certain dates but I always get an empty result even though there is a lot of data. This is for a custom post type. $args = array( 'post_type' => 'bookings', 'fields' => 'ids', 'post_status' => 'any', 'posts_per_page' => -1, 'date_query' => array( array( 'after' => '2022-01-01', 'before' => '2022-06-01', 'inclusive' => true, ), ) ); $data = get_posts($args); die(var_dump($data)); I also tried something like the below to get a specific …
I have a frustrating issue. I am using the date_query as referenced in the Codex: <?php $today = getdate(); $args = array( 'post_type' => 'Lighting', 'post_status' => 'publish', 'posts_per_page' => 1, 'date_query' => array( array( 'year' => $today['year'], 'month' => $today['mon'], 'day' => $today['mday'], ), ), ); $the_query = new WP_Query( $args ); While I can display custom posts as expected if I exclude 'day', I get no posts when it is included in the query. I am using Advanced …
I'm building a listings website using WooCommerce. A listing is either set to live or sold inside of a custom field key status Once a listing is sold then the custom field status is updated with sold. This allows the listing to be hidden from the website, yet still able to be viewed directly, just in case users still click a link and end up on the listing page. I am looking to automatically delete (or move to trash for …
I am a little confused by this. I have a query that finds posts within a category and date. I can filter the categories, but I have no idea how to filter by date. The query works. I see all of the posts I have queried, but I don't know how to filter the date. It would help if I knew what was meant to appear in the url The search for categories returns /blog/?category=promotions What should a date filter …
I'm trying to apply a Datefilter for specific categories. Wordpress crashs with a out of memory error. Is this a server problem or is my query wrong? At first I tried query -> (...) but with approach I get an error, cause of too few arguments. While using query = new WP_Query... I get the out of memory error. Thank you for your help. My code: function test_filter( $query ) { $options = get_option('dh_options'); $cats = "54,55,56"; if ($options['checkbox_usr_q'] == …
I need to create a very complex post query, but I don't know if such a query can exist, or if I have to write PHP code to combine the results of two different queries... Let me please describe the situation first, and then write what I've done so far. So, I need to return results from a CPT. The CPT has its own taxonomy, where I've inserted the necessary terms. The terms have to do with different genre of …
Hello I have code intended to get the most viewed post for last 2 days and it seems like not working or maybe my code is just incorrect. I appreciate any help. Thanks. $args = array( 'post_type' => 'post', 'meta_key' => 'post_views_count', 'orderby' => 'meta_value_num', 'date_query' => array( array( 'after' => '2 days ago', ) ) ); $the_query = new WP_Query( $args ); // The Loop if ( $the_query->have_posts() ) { echo '<ul class="posts-list">'; while ( $the_query->have_posts() ) { $the_query->the_post(); …
I have specific category, in what I have a lot of posts. Every post starts from, for example 21 october 2019. I have this code to show posts in the correct sequence: class GoroskopController { static function get_data($parent_id, $number, $heading, $heading_color = 'dark') { $loop = new \WP_Query(GoroskopModule::loop_args($parent_id, $number)); if ($loop->have_posts()) : echo '<div class="goroskop-block mb30">'; echo '<div class="block-heading-color-small -' . $heading_color . ' font-sans">' . $heading . '</div>'; while ($loop->have_posts()) : $loop->the_post(); $this_date = self::this_gor(get_the_title()); include "templates/block.php"; endwhile; wp_reset_query(); …
I'm using this code for generating a Feed from lasted modified post mysqli_query( $conn, "SELECT * FROM wp_posts WHERE post_status = 'publish' AND post_type = 'post' AND DATE(post_modified) > DATE(post_date) ORDER BY post_modified DESC LIMIT 50" ); and it works perfect, now I need to reproduce in a WordPress plugin and I use this code: $lastupdated_args = array( 'paged' => $paged, 'orderby' => 'modified', 'ignore_sticky_posts' => '1' ); but in this case it shows all posts ordered my latest modification …
I'm doing a WP_Query with a date_query parameter after, and I want the nearest post after that date, but I get the farest ones in the future from the date. Is there any parameter to control this? something like 'near_to' => 'past/future', or WP_Query always retrieve the most recent? This is my code: $my_query = new WP_Query(array( 'post_type' => 'event', 'posts_per_page' => 1, 'date_query' => array( 'after' => date('Y-m-d h:i',time()) ) )); I have an events site, and I want …
Goal: After each post (that contains under a certain amount of words), display the two posts that were published before it in that category/tab. I found this on stack, where they do something similar, but they're displaying the 2 most recent posts. I want to display the 2 that were published before the currently-read article, though. Is there a way to modify this code?
I am trying to query my post for several date ranges which are specifically posts that are published in 24 hours, within 7 days, posts that are two weeks old, and posts older than 2 weeks. I am able to easily query the posts if I am trying to query a specific date range for example, posts from 24 hours. What I am struggling with right now is I am not certain how to query the posts when two date …
I'm building a weekly leaderboard and trying to display posts from on the current calendar week Monday to Sunday. I've tried the code below, but it's only retrieving a post from today (Tuesday 1st January) and no posts from the day before (Monday 31st December). Any ideas? Thanks! $args = array( 'date_query' => array( array( 'year' => date( 'Y' ), 'week' => date( 'W' ), ), ), 'post_type' => 'ride', 'posts_per_page' => 99, 'order' => 'DEC', ); $leaders = new …
I'm using the following query to extract all products which are not in the 'Service' product category and order them by a custom meta field '_vintage_age'. $q->set( 'tax_query', array(array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => array( 'Service' ), 'operator' => 'NOT IN' ))); $q->set('meta_query',array(array( 'vtp_age' => array( 'key' => '_vintage_age', 'value' => array(1,2,3), 'compare' => 'IN' )))); $q->set('orderby',array( 'vtp_age' => 'ASC', 'date' => 'ASC' )); I now need to extend this query to EXCLUDE products which have been …
I want to filter my RSS feed to only show posts in the previous calendar month. I have this code in my theme functions file but it is not working? // filter the RSS feeds to show only the last calendar month $lastMonthNumber = date( 'n', current_time( 'timestamp' ) ) - 1; // work out the previous month number function feedFilter($query) { if ($query->is_feed) { $query->set('date_query', array( array( 'month' => $lastMonthNumber //'month' => 5 ) )); } return $query; } …
I need to modify search query in my theme to add date_query with 'after' param based on option value from form select. Here's what I got so far: Inside form my select looks like: <select class="select-date" id="select-date"> <option value="5">For the whole time</option> <option value="1">For one day</option> <option value="2">For 3 days</option> <option value="3">For week</option> <option value="4">For month</option> </select> Values must filter content based on date posts were posted. For example selected value of 3 gives us posts published in the last …
I'm writing an on this day function which should show the X number of posts for the current day and month. How can I add a fallback to the query if there are no posts, to show the next available day of posts? These are the arguments I'm passing to the current day query. $onThisDay_args = array( 'post_type' => array('on-this-day'), 'posts_per_page' => $postlimit, 'date_query' => array( array( 'month' => date( 'n', current_time( 'timestamp' ) ), 'day' => date( 'j', current_time( …
I need to output popular posts in a blog using several params: Not older than one week; Rating is over than 250; Order by date Here is my code: function evanre_custom_order_query( $query ) { if ( is_admin() || ! $query->is_main_query() ) { return; } $query_var_show = get_query_var( 'show' ); if ( empty( $query_var_show ) ) { return; } if ( 'popular' === $query_var_show ) { $query->set( 'orderby', 'date' ); $query->set( 'meta_query', array( array( 'key' => 'blt_upvotes', 'value' => 250, 'compare' …