Saturday, December 10, 2022
HomeWordPress DevelopmentWP Question + customized fields: Learn how to question occasion posts from...

WP Question + customized fields: Learn how to question occasion posts from the present date backwards 6 months and set up it month by month?


I’m having some hassle determining the logic of this question and what I must do to make it work.

I created an “Occasion” customized submit kind, and each Occasion submit has a date worth coming from a customized area.

I wish to show on my web page Occasion posts from the present date till 6 months again, organized month by month (picture on the finish of this submit)

I’m form of misplaced with that job.

That is the place I arrived to this point, I can retrieve the posts backward from my present day on, however I’m nonetheless undecided the right way to show them month by month (underneath a button for each month).

<?php
    // Question

    $the_query = new WP_Query(array(
        'post_type' => 'occasion',
        'posts_per_page' => -1,
        'meta_key' => 'date_picker',
        'orderby' => 'meta_value',
        'order' => 'DESC',
        'meta_query' => array(
            array(
                'key' => 'date_picker',
                'worth' => date('Ymd'),
                'examine' => '<=',
                'kind' => 'DATE'
            )
        )
    ));

    ?>

    <?php if ($the_query->have_posts()) : ?>
    <?php whereas ($the_query->have_posts()) : $the_query->the_post();

            // vars for contemporary
            $event_image = get_field('event_image');
            $date_picker = get_field('date_picker');
            $time_picker = get_field('time_picker');
            $event_location = get_field('event_location');
            $label_opt = get_field_object('label_options');

        ?>


    <div class="event-col">
        <div class="event-thumb-image">

            <img src="<?php echo $event_image ?>" alt="occasion">

            <!-- add labels -->
            <?php if (!empty($label_opt)) : ?>

            <?php $labels = $label_opt['value']; ?>


            <div class="event-labels">
                <?php foreach ($labels as $label) : ?>

                <?php if ($label == '1') : ?>
                <span class="label">Profis</span>
                <? elseif ($label == '2') : ?>
                <span class="label">Workshop</span>
                <? endif; ?>

                <?php endforeach; ?>
            </div>
            <?php endif; ?>

        </div>

        <div class="event-thumb-text">
            <div>
                <h2><?php the_title(); ?></h2>
            </div>

            <div>
                <span class="latest-events-date">
                    <?php
                            // change date format
                            $format_in = 'D, d.m.y';
                            $format_out="M";

                            $date = DateTime::createFromFormat($format_in, $date_picker);

                            echo $date->format($format_out);
                            ?>
                </span>
                <span class="latest-events-time-place"><?php echo $time_picker ?> -
                    <?php echo $event_location ?></span>
            </div>
        </div>
    </div>
    <?php endwhile; ?>
    <?php endif; ?>

    <?php wp_reset_query(); ?>

That is the web page I’m growing, no success but.

enter image description here

Thanks lots <3

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments