hello
i need to display the today posts and tomorrow posts from a custom type (post-date). So if the today date is the same then show the posts.
i have this code
<?php
// get posts
$posts = get_posts(array(
'post_type' => 'post',
'posts_per_page' => -1,
'meta_key' => 'post-date',
'orderby' => 'meta_value_num',
'order' => 'ASC'
));
if( $posts ): ?>
<ul>
<?php foreach( $posts as $post ):
setup_postdata( $post )
?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?> (date: <?php the_field('post-date'); ?>)</a>
</li>
<?php endforeach; ?>
</ul>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
I wanna display only the current date posts
Hi @pansotdev
I believe you can do it like this:
$posts = get_posts(array(
'post_type' => 'post',
'posts_per_page' => -1,
'meta_key' => 'post-date',
'meta_value' => date("Ymd"),
'orderby' => 'meta_value_num',
'order' => 'ASC'
));
Hope this helps.
I try it and doesn’t work
Hi @pansotdev
I’ve just tested it on my end, and it was working as expected. Could you please share the JSON or XML export of your field group so I can test it out in my installation?
Thanks!
I solved
'meta_value' => date('d-m-Y'),
It was the wrong format.
Now i try to show the same results +1 day
Hi @pansotdev
I’m glad you solved it.
To get the next date, you can add 1 to the date and use “meta_query” to query multiple rules. This page should give you more idea about it: https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters.
I hope this helps.