• Resolved bartleriche

    (@bartleriche)


    So I’m printing out all of the posts of the post type ‘agenda_item’. They are ordered on the value of a custom field called ‘agenda-datum’. This custom field contains a date formatted in the database like this ‘yyyymmdd’.

    The posts are ordered correctly, accept for these ones:
    20130929
    20130825
    20131103

    They should be ordered like this ofcourse:
    20130825
    20130929
    20131103

    Strange right? Anyone got an idea why this is happening?

    Here’s my code:

    <?php
    query_posts( array (
    	'post_type' => 'agenda_item',
    	'meta_key' => more_fields("agenda-datum"),
    	'orderby' => 'meta_value',
    	'order' => 'ASC'
    ) );
    
    while ( have_posts() ) : the_post();
    	// This prints the custom field value of 'agenda-datum'
    	more_fields("agenda-datum");
    endwhile;
    wp_reset_query();
    ?>

    Thanks!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Shouldn’t you be “orderby” from the “meta_key”?

    Like so:

    <?php
    query_posts( array (
    	'post_type' => 'agenda_item',
    	'meta_key' => more_fields("agenda-datum"),
    	'orderby' => 'meta_key',
    	'order' => 'ASC'
    ) );
    
    while ( have_posts() ) : the_post();
    	// This prints the custom field value of 'agenda-datum'
    	more_fields("agenda-datum");
    endwhile;
    wp_reset_query();
    ?>

    Thread Starter bartleriche

    (@bartleriche)

    Hi Josh!

    Thanks for your help, but when I gave your suggestion a try it didn’t change anything. Still the same problem…

    What is the meta key->value pair of one of your custom post types of ‘agenda_item’?

    Thread Starter bartleriche

    (@bartleriche)

    I’m sorry Josh, I don’t get your question. Can you be a little more specific? Thanks!

    Thread Starter bartleriche

    (@bartleriche)

    So I refined my code, ‘orderby’ => ‘meta_value_num’,: should work better for numbers… Still doesn’t work right though.. I still get the incorrect order :/

    <?php
    query_posts( array (
    	'post_type' => 'agenda_item',
    	'meta_key' => more_fields("agenda-datum"),
    	'orderby' => 'meta_value_num',
    	'order' => 'ASC'
    ) );
    
    while ( have_posts() ) : the_post();
    	echo get_post_meta( $post->ID, 'agenda-datum', true);
    endwhile;
    
    wp_reset_query();
    ?>

    Man, I’m so sorry, but I just received a call and half to jump up and run out.

    If you are unable to resolve this.. please send me a personal email:
    https://joshlobe.com/contact-me/

    Please include a link to this thread, so I know who you are. As soon as I return home, I’ll be checking up on you ??

    Good luck until then!!

    Thread Starter bartleriche

    (@bartleriche)

    Thanks a lot Josh! Anyone else who know what the cause of this bug might be?

    Did you try using just agenda-datum as the meta_key? Or does your plugin require you to use more_fields(“agenda-datum”)?

    I used something like this for a site I recently did and that worked out fine:

    array(
       'post_type'=> 'agenda_item',
       'orderby'  => 'meta_value',
       'meta_key' => 'agenda-datum',
       'order'    => 'asc'
    )
    Thread Starter bartleriche

    (@bartleriche)

    Senff, you just made my day. That did the trick! Thanks so much!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Incorrect date list order with query_posts’ is closed to new replies.