• Hi guys,

    I explain my little problem.

    I have 2 custom meta one for the start date of my event et one for the end date of my event and I need to order my events according to the start date and to remove them when the end date is over.

    Meta:

    Start date: date_de_levenvement
    End date: date_de_fin

    Here is my loop:

    <?php query_posts( 'post_type=agenda&meta_key=date_de_fin&meta_compare=>=&meta_value=' . $todaysDate . '&orderby=meta_value&order=ASC'); ?>
    <?php while ( have_posts() ) : the_post(); ?>
    <?php
    $date = get_field('date_de_fin');
    $newDate = date("d/m/Y", strtotime($date)); ?>

    Just need to change the query but I don’t know how to use 2 parameters with the meta value.

    Thanks a lot,

    Jhon

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter jhonb

    (@jhonb)

    Well in this case, the &orderby=meta_value need to be something like &orderby=”date_de_levenement”

    ??

    Thread Starter jhonb

    (@jhonb)

    Tried another technique but does not work. Here is my paste bin

    https://pastebin.com/eRMQBvFz

    Thanks a lot guys ??

    Thread Starter jhonb

    (@jhonb)

    Ok got the answer. For those who want it

    $args = array(
            'post_type' => 'agenda',
            'meta_key' => 'date_de_levenvement',
            'meta_query' => array(
                array(
                    'key' => 'date_de_fin',
                    'value' => $todaysDate,
                    'compare' => '>='
                    )
                ),
            'orderby' => 'meta_value meta_value_num',
            'order' => 'ASC'
            );
    
    $your_custom_query = new WP_Query($args);
    
    // The Loop
    if ( $your_custom_query->have_posts() ) {
        while ( $your_custom_query->have_posts() ) {
            $your_custom_query->the_post();
            // your code goes here
        }
    } else {
        // no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();

    Thanks to Jared Cobb

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to order post by date > custom meta !’ is closed to new replies.