Topic: Filter posts by date | WP Masonry Layout

Filter posts by date

Home Forums Lite Version Filter posts by date

This topic contains 3 replies, has 2 voices, and was last updated by  Mel 1 year, 12 months ago.

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

    Mel

    Hi,

    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.

    wp-content/plugins/wp-masonry-layout/includes/admin/shortcode/wml_add_edit_shortcode.php
    Around line 170 I added:

                        <tr>
                            <td>Date from</td>
                            <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>
                        </tr>
    
                        <tr>
                            <td>Date to</td>
                            <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" />
                            </td>
                        </tr>
    

    wp-content/plugins/wp-masonry-layout/plugin_interface.php
    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(
                    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;
            }
    

    wp-content/plugins/wp-masonry-layout/includes/admin/shortcode/wml_shortcodes.php
    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

    Mel

    Oops….pressed on submit to soon 🙂

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

    #2940 Reply

    Masonry Guy
    Keymaster

    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

    Mel

    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: