Sort Both by Publication Date and by Update

Asked

Viewed 197 times

0

Guys I’m setting up an Index and I’m trying to do the following... I will have this 'mini highlight' and at the moment I managed to order it by only DATA, but a few times the news will be updated and I would like this news rise based TBM on the modification date. Here’s 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>
  • Inside your orderby, try to insert array( 'date' => 'ASC', 'date_update' => 'ASC' )

  • Maybe this link can help you https://wordpress.stackexchange.com/questions/65769/multiple-orderby-values-in-wp-query

  • Working it is working, I just made a change, the problem that is disappearing with the posting thumbnail

  • I was analyzing the posts, it is not working according to the update and publication date.

1 answer

1


If a post has been published and has not been modified, the update date is the same as the publication date, then 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'
));

Behold Order and Orderby Parameters in the official documentation.

  • Look I had tried modified but at the time I tested I believe I did not pay attention on the functioning, but that way you quoted worked perfectly, thank you very much =)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.