WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Posts are showing up in ascending order (5 posts)

  1. iampontus
    Member
    Posted 9 months ago #

    Hello forum!

    I'm new to wp and I have a problem related to posts showing up in wrong order. The site has categories for posts, and all posts with the category 'Events' are showing up in ascending order for some reason (old events are showing on top). I would like the posts under "Upcoming Events" to show up in the same order as under "Latest News", with the most recent post on top.
    I've dubble checked that time zone is correct and there is no "sticky posts" used. I'm don't think is related to plugin conflicts, since it only applies to Event-posts.
    I'm sure there is an easy explanation why, and I would be truly grateful for any help fixing this!

    The site is: dutchchamber.se

    Kind Regards

  2. alchymyth
    Forum Moderator
    Posted 9 months ago #

    can you post a direct link to the web page where this happens?

    I checked the 'events' category archive page, and the post order seems to be normal with the latest post at the top.

  3. iampontus
    Member
    Posted 9 months ago #

    Thanks for your quick response (unlike my own...) This would be at the main page under the headline "Upcoming Events", but also under the link for events. The event on top shows a post for an event in August, and at the bottom the an event for December is showing. This is of course "event dates" and not publish dates, however the post for the top event was published back in July and the newest one is from earlier this month.

    Many thanks for you assistance!

  4. alchymyth
    Forum Moderator
    Posted 9 months ago #

    the direct link for 'events' is going to a page which is using a page template page-events.php

    what is the full code of that page template?

  5. iampontus
    Member
    Posted 9 months ago #

    Thanks to your guidance I was able to locate the code to modify. The order for both page-events.php and front-page.php had order set to ASC. This I changed to DESC which solved the problem.

    Thanks again for brilliant help!

    (Posted the code below incase it could help other rookies out there)

    <h2>Upcoming events</h2>
                    <hr>
                    <?php
                    $args = array(
                        'numberposts' => 5,
                        'meta_key' => 'start_date',
                        'orderby' => 'meta_value',
                        'order' => 'DESC', // Changed from ASC
                        'meta_query' =>array(
                            array(
                                'key' => 'show_on_front_page',
                                'value' => '1'
                            )
    
                        )
                    );

Reply

You must log in to post.

About this Topic