Support » Plugin: WP Show Posts » Order By Custom Date Field

  • Hi,
    I’m using WP Show Posts to display posts and events. I have a plugin that creates a date and time field and turns a post into an event. I’m trying to order the posts by the date_begin meta field but I can’t seem to get it working.

    I have used the following code to change the display of the date to “Monday 1st September 2019” etc,

    add_action( 'wpsp_before_content','wpsp_add_custom_meta' );
    function wpsp_add_custom_meta()
        $meta = get_post_meta( get_the_ID(), 'event_begin', true );
        if ( isset( $meta ) && '' !== $meta )
           echo '<div class="event_datelist">'.esc_attr( date('l jS \of F Y', strtotime( $meta ))).'</div>';

    and I think that the orderby date_begin is now taking the first letter of the date the way it is displayed… so on it shows Mondays then all the Tuesdays etc…

    The shortcode that I’m trying to get working is this:
    [wp_show_posts id="548" settings="orderby=event_begin&order=DESC"]

    I also tried to make a function but I get an error at the end and can’t get it to work properly.

    add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
        if ( 548 === $settings['list_id'] ) {
    $args = array(
    'orderby' => 'event_begin',
    'order'   => 'DESC',
        return $args;
    } 10, 2 );

    Any help would be appreciated,

    The page I need help with: [log in to see the link]

  • The topic ‘Order By Custom Date Field’ is closed to new replies.