-
-
Save pavlo-bondarchuk/c127de348023072de5a46dbb8e6246f6 to your computer and use it in GitHub Desktop.
wp_query sort post by acf datepicker / current, future and past
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*display current post -> startdate<=today...enddate>=today */ | |
<?php | |
$today = date('Ymd'); | |
$date_args = array ( | |
'post_type' => 'post', | |
'category_name' => '....',/*name category posts*/ | |
'meta_key' => 'start_ico', | |
'posts_per_page' => -1, | |
'orderby' => 'meta_value_num', | |
'order' => 'ASC', | |
'meta_query' => array( | |
array(/*bottom limit*/ | |
'key' => 'start_ico', | |
'compare' => '<=', | |
'value' => $today, | |
), | |
array(/*top limit*/ | |
'key' => 'end_ico', | |
'compare' => '>=', | |
'value' => $today, | |
) | |
), | |
); | |
$date_query = new WP_Query( $date_args );?> | |
<?php if( $date_query->have_posts() ): ?> | |
<?php while ( $date_query->have_posts() ) : $date_query->the_post(); ?>/*start query*/ | |
... | |
<?php /*display future post*/ | |
$today = date('Ymd'); | |
$date_args = array ( | |
'post_type' => 'post', | |
'category_name' => 'ico', | |
'meta_key' => 'start_ico', | |
'posts_per_page' => -1, | |
'orderby' => 'meta_value_num', | |
'order' => 'ASC', | |
'meta_query' => array( | |
array( | |
'key' => 'start_ico', | |
'compare' => '>=', | |
'value' => $today, | |
), | |
), | |
); | |
$date_query = new WP_Query( $date_args );?> | |
<?php if( $date_query->have_posts() ): ?> | |
<?php while ( $date_query->have_posts() ) : $date_query->the_post(); ?> | |
... | |
<?php /*display end post*/ | |
$today = date('Ymd'); | |
$date_args = array ( | |
'post_type' => 'post', | |
'category_name' => 'ico', | |
'meta_key' => 'start_ico', | |
'posts_per_page' => -1, | |
'orderby' => 'meta_value_num', | |
'order' => 'ASC', | |
'meta_query' => array( | |
array( | |
'key' => 'end_ico', | |
'compare' => '<=', | |
'value' => $today, | |
), | |
), | |
); | |
$date_query = new WP_Query( $date_args );?> | |
<?php if( $date_query->have_posts() ): ?> | |
<?php while ( $date_query->have_posts() ) : $date_query->the_post(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment