I want to show the post dates of posts which is greater than $postdate
value.
what is the wrong with the following code?
Instead of filtering the data by dates, it shows all the dates. I do not know what the problem is with the logic.
Any help will be most appreciated.
$postdate = get_the_date('Y-m-d');
$update = new WP_Query(array(
'posts_per_page' => -1,
'post_type' => 'post',
'meta_key' => 'post_date',
'orderby' => 'meta_value_num',
'order' => 'ASC' ,
'meta_query' => array(
array(
'key' => 'post_date',
'compare' => '>',
'value' => $postdate,
'type' => 'numeric'
)
)
));
while ($update->have_posts()) {
$update->the_post(); ?>
<p class="center">
<span><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span><br>
<span class="small"><i><?php the_date(); ?></i></span>
</p><?php
} ?>
I want to show the post dates of posts which is greater than $postdate
value.
what is the wrong with the following code?
Instead of filtering the data by dates, it shows all the dates. I do not know what the problem is with the logic.
Any help will be most appreciated.
$postdate = get_the_date('Y-m-d');
$update = new WP_Query(array(
'posts_per_page' => -1,
'post_type' => 'post',
'meta_key' => 'post_date',
'orderby' => 'meta_value_num',
'order' => 'ASC' ,
'meta_query' => array(
array(
'key' => 'post_date',
'compare' => '>',
'value' => $postdate,
'type' => 'numeric'
)
)
));
while ($update->have_posts()) {
$update->the_post(); ?>
<p class="center">
<span><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span><br>
<span class="small"><i><?php the_date(); ?></i></span>
</p><?php
} ?>
Share
Improve this question
edited Mar 25, 2020 at 2:45
WordPress Speed
2,2833 gold badges19 silver badges34 bronze badges
asked Jan 4, 2020 at 18:26
AshurAshur
233 silver badges8 bronze badges
7
|
Show 2 more comments
1 Answer
Reset to default 3Ashur
Please try following code with date_query. this is working fine at my end. Let me know if you want any additional detail.
<?php
$postdate = get_the_date('Y-m-d');
$args = array(
'posts_per_page' => -1,
'post_type' => 'post',
'date_query' => array(
'after' => $postdate,
)
);
$update = new WP_Query($args);
while ($update->have_posts()) {
$update->the_post();
$post_id = get_the_ID();
$post_title = get_the_title();
$post_date = get_the_date();
$post_link = get_the_permalink();
?>
<p class="center">
<span><a href="<?php echo $post_link; ?>"><?php echo $post_title; ?></a></span><br>
<span class="small"><i><?php echo $post_date; ?></i></span>
</p>
<?php } ?>
'
you'll get a screen of death for invalid PHP code – Tom J Nowell ♦ Commented Jan 4, 2020 at 19:13'
is still missing so the code in your question would generate PHP fatal syntax errors, and it breaks the syntax highlighting. Also update the question to explain where and how this code is being ran – Tom J Nowell ♦ Commented Jan 4, 2020 at 23:04