Support

Account

Home Forums General Issues Can't sort my news

Solved

Can't sort my news

  • Hi,
    First, thank you very much for this beautifully plugin! I love it! 🙂

    At this moment i create a news page and every news/post has a custom field called ‘news_date’. The aim is to sort the news by that field. I’ve already read your documentation, but it will not work 🙁

    Here is a piece of my template code:

    $args = array(
    	'cat' => 3,
    	'posts_per_page' => 6,
    	'paged' => get_query_var('paged'),
    	'meta_key' => 'news_date',
    	'orderby' => 'meta_value_num',
    	'order' => ASC
    );
    
    query_posts( $args );
    while ( have_posts() ) : the_post();
    $newsId = get_the_ID();
    <div class="news">
    ...
    <span class="news_date"><?php the_field('news_date', $newsId); ?></span>
    ...
    </div>
    endwhile;

    Please tell me what’s wrong? :/

    Tank you very much!

  • Hi @Bountalis

    I have no idea what is wrong with your code.

    You forgot to mention what does and doesn’t work!
    Have you debugged the issue?
    Have you read the brand new ‘how to’ guide for ordering a query?
    Have you tried using get_posts?
    Have you tried using WP_Query?

  • Hi Elliot,

    Thanks for answering.
    My english is not the best, but i try to explain my problem.
    I add a screenshot, here you can see the crazy order of my posts.

    Yes, i’ve used your “how to” guide, but no matter what approach I use, it stays the same result.

    The posts are not in order and the aim is to sort it like newest -to-> older ones. The newest post starts from 03.06.2013 and the oldest and last post have to be the 01.09.2011.

    I dont know, whats going wrong, every post has a date field (Date Picker, save and display format: dd.mm.yy). When i remove the “meta_key” and “orderby” arguments, it changes the order. So i think the query reacts to this arguments …but nevertheless something is going wrong.

    Thanks for trying to help me! 🙂

  • Oh, i recognize a pattern. He sorted only by the days and ignore the date as a whole. :/

  • I have change the save format back to yymmdd and edit the order in my template per date('d.m.Y', strtotime($myCustomFieldDate));.

    My own fail, sorry 😀

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Can't sort my news’ is closed to new replies.