Skip to main content
deleted 11 characters in body
Source Link
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209

All I'm trying to do here is a simple custom loop using WP_Query to display posts if they are published in the last 24 hours; otherwise, a message appears telling the user to check back soon for fresh posts. I'm trying to use the date_query parameter in my arguments but I'm getting unexpected results...at first it will work, but if I check the page in a few minutes, its as if it reset itself... my loop is set up below:

$args = array(
                'post_type' => 'surf_reports',
                'posts_per_page' => '1',
                'category_name' => $cat (this is pulled dynamically in my template),
                'date_query' => array(
                        'before' => strtotime('-24 hours')
                    )
 
                );

And then obviously below there would be a loop, I'm not going to share that bc its standard and I believe unrelated to the issue.

All I'm trying to do here is a simple custom loop using WP_Query to display posts if they are published in the last 24 hours; otherwise, a message appears telling the user to check back soon for fresh posts. I'm trying to use the date_query parameter in my arguments but I'm getting unexpected results...at first it will work, but if I check the page in a few minutes, its as if it reset itself... my loop is set up below:

$args = array(
                'post_type' => 'surf_reports',
                'posts_per_page' => '1',
                'category_name' => $cat (this is pulled dynamically in my template),
                'date_query' => array(
                        'before' => strtotime('-24 hours')
                    )
 
                );

And then obviously below there would be a loop, I'm not going to share that bc its standard and I believe unrelated to the issue.

All I'm trying to do here is a simple custom loop using WP_Query to display posts if they are published in the last 24 hours; otherwise, a message appears telling the user to check back soon for fresh posts. I'm trying to use the date_query parameter in my arguments but I'm getting unexpected results...at first it will work, but if I check the page in a few minutes, its as if it reset itself... my loop is set up below:

$args = array(
    'post_type' => 'surf_reports',
    'posts_per_page' => '1',
    'category_name' => $cat (this is pulled dynamically in my template),
    'date_query' => array(
            'before' => strtotime('-24 hours')
    )
);

And then obviously below there would be a loop, I'm not going to share that bc its standard and I believe unrelated to the issue.

Source Link
la1ch3
  • 135
  • 2
  • 9

Only display post if published in last 24 hours?

All I'm trying to do here is a simple custom loop using WP_Query to display posts if they are published in the last 24 hours; otherwise, a message appears telling the user to check back soon for fresh posts. I'm trying to use the date_query parameter in my arguments but I'm getting unexpected results...at first it will work, but if I check the page in a few minutes, its as if it reset itself... my loop is set up below:

$args = array(
                'post_type' => 'surf_reports',
                'posts_per_page' => '1',
                'category_name' => $cat (this is pulled dynamically in my template),
                'date_query' => array(
                        'before' => strtotime('-24 hours')
                    )

                );

And then obviously below there would be a loop, I'm not going to share that bc its standard and I believe unrelated to the issue.