Topic: Filter posts by date | WP Masonry Layout

Filter posts by date

Home Forums Lite Version Filter posts by date

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #2922 Reply


    I have made a adjusment for this plugin, so that you can filter posts by date. Off course, this is at YOUR OWN RISK and has no further filtering by post type.
    Also remember that this adjustment is gone when you update the plugin (maybe the author can add this?)!
    Maybe someone can use this if they need it.

    Around line 170 I added:

                            <td>Date from</td>
                                <input type="date" maxlength="10" placeholder="yyyy-mm-dd" name="wmlo_date_from" value="<?php echo wml_fill_up_form($shortcodeDetails, 'wmlo_date_from'); ?>" class="medium date" />
                            <td>Date to</td>
                                <input type="date" maxlength="10" placeholder="yyyy-mm-dd" name="wmlo_date_to" value="<?php echo wml_fill_up_form($shortcodeDetails, 'wmlo_date_to'); ?>" class="medium date" />

    Around line 143 I added:

            if ($shortcodeData['wmlo_date_from'] != '' && $shortcodeData['wmlo_date_to'] != ''){
                //Convert date_from
                $date_from = strtotime($shortcodeData['wmlo_date_from']);
                $date_from_d = date('d',$date_from);
                $date_from_m = date('m',$date_from);
                $date_from_y = date('Y',$date_from);
                //Convert date_to
                $date_to = strtotime($shortcodeData['wmlo_date_to']);
                $date_to_d = date('d',$date_to);
                $date_to_m = date('m',$date_to);
                $date_to_y = date('Y',$date_to);
                //Create dateArray
                $dateArray = array(
                        'after'     => array(
                            'year'  => $date_from_y,
                            'month' => $date_from_m,
                            'day'   => $date_from_d,
                        'before'    => array(
                            'year'  => $date_to_y,
                            'month' => $date_to_m,
                            'day'   => $date_to_d,
                        'inclusive' => true,
                $query_arg['date_query'] = $dateArray;

    Around line 25 I added:

    'wmlo_date_from' => $_POST['wmlo_date_from'],
    'wmlo_date_to' => $_POST['wmlo_date_to'],

    Again, this is at YOUR OWN RISK!! I am not responsible for any damage or issues you encounter doing this.

    #2923 Reply

    Oops….pressed on submit to soon 🙂

    You can now edit or add the dates to the shortcode.

    #2940 Reply
    Masonry Guy

    Hi Mel,

    Really a great addition. Thank you so much for it.

    However, i will wait for some other users to ask for this features. And if we can have more, then we will keep this in upcoming release.

    Thanks 🙂

    #3020 Reply

    You are welcome 😉 If you need any help, let me know.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Filter posts by date
Your information: