Sort As By Date Of Publication As By Update

0

I'm setting up an Index and I'm trying to do the following ... I'm going to have this 'mini highlight' and at the moment I was able to sort it for DATE only, but sometimes the news will be updated and I would like this news to rise based on TBM on the modification date. Here is the code for you to analyze!

<div class="news-wrap" id="news-section">
                        <div class="row">
                            <div class="col-md-4">
                                <section class="news">
                                    <h4 class="section-title">
                                        <a href="<?= get_site_url(null, 'category/eventos-e-lazer') ?>" target="_self">Eventos</a>
                                    </h4>
                                    <?php

                                    $posts = get_posts(array(
                                        'numberposts'   => 4,
                                        'post_type'     => 'post',
                                        'category_name' => 'eventos-e-lazer',
                                        'orderby'       => 'date',
                                        'order'         => 'DESC'
                                    ));

                                    $count = 0;

                                    foreach ($posts as $post):

                                        setup_postdata($post);

                                        if($count == 0): ?>
                                            <article class="news-destaque">
                                                <a href="<?php the_permalink(); ?>">
                                                    <figure>
                                                        <img src="<?php the_post_thumbnail_url($post->ID, 'ag-apcef-large'); ?>" alt="<?php the_title(); ?>">
                                                    </figure>
                                                    <div class="title"><?php the_title(); ?></div>
                                                </a>
                                                    <div class="content">
                                                        <?php the_excerpt(); ?>
                                                    </div>

                                                <a href="<?php the_permalink(); ?>" class="link">Leia mais</a>

                                            </article>
                                        <?php else: ?>
                                            <article class="news-reduced">
                                                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                            </article>
                                        <?php endif;

                                        $count++;

                                    endforeach; ?>
                                </section>

                                <a href="<?= get_site_url(null, 'category/eventos-e-lazer') ?>" class="btn-list-all" target="_self">Veja todos</a>
                            </div>
    
asked by anonymous 03.08.2017 / 15:46

1 answer

1

If a post has been published and has not been modified, the update date is the same date as the posting, so you can simply use the update date:

$posts = get_posts(array(
    'numberposts'   => 4,
    'post_type'     => 'post',
    'category_name' => 'eventos-e-lazer',
    'orderby'       => 'modified',
    'order'         => 'DESC'
));

See Order and Orderby Parameters in the official documentation.

    
04.08.2017 / 14:41