Support

Account

Home Forums General Issues Display post list, ordered by expiry date

Unread

Display post list, ordered by expiry date

  • I need to display a list of posts, ordered by an ACF date picker field (end_date). This is essentially an ‘ending soon’ list. I’m using the Divi theme and so would like to have this as a shortcode I can use to place the list anywhere within the builder.

    I have looked in to using the Post Expirator plugin to list posts that ‘expire soon’, but to no avail.

    My PHP is pretty basic so any help would be greatly appreciated.The below did not work, probably I’m sure for very obvious reasons that are above my ability.

    function sort_query_order( $query ) {
        $currentdate = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
    
    $wp_query = new WP_Query(  array (
        'post_type' => 'post',
        'meta_query'=> array(
            array(
              'key' => 'end_date',
              'compare' => '>',
              'value' => $currentdate,
              'type' => 'DATE',
            )),
        'meta_key' => 'end_date',
        'orderby' => 'meta_value',
        'order' => 'ASC',
    	'posts_per_page' => 12,
    	'paged' => $paged,
        )
    );
    }
    add_shortcode( 'ending_posts', 'sort_query_order' );
Viewing 1 post (of 1 total)

The topic ‘Display post list, ordered by expiry date’ is closed to new replies.