• Resolved thomas

    (@beloutte)


    hi,

    I try to order some posts by ID but it doesn’t seem to work…

    here is my code :

    <?php if (have_posts()) : ?>
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("category_name=concerts&orderby=ID&paged=$paged"); ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="post-sum" id="post-<?php if ( get_post_meta($post->ID, 'date', true) ) { ?><?php echo get_post_meta($post->ID, "date", $single = true); ?><?php } ?>">

    I used a custom field to have specific IDs (reverse date) to order post by concert date and not post publication date…

    here is the page : http://mascarel.eu/agenda/

    what’s wrong with orderby=ID ???
    until now it’s been working but each new post appears on top, ignoring the ID…

    please help !

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Why not order by the date in the custom field “date”? If you have it formatted to yyyy-mm-dd. Then you can sort by using something like this:

    $args = array(
       'meta_key' => 'date',
       'orderby' => 'meta_value',
    );
    query_posts($args);

    Thread Starter thomas

    (@beloutte)

    many thanks !
    but how can I used this with the other query_posts values ?

    like this maybe ? :

    <?php if (have_posts()) : ?>
    <?php
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $args = array(
           'meta_key' => 'date',
           'orderby' => 'meta_value',
           'category_name'  => 'concerts',
           'paged' => '$paged'
        );
    query_posts($args); ?>
    Moderator keesiemeijer

    (@keesiemeijer)

    like this maybe?

    Yes exactly like that.

    New posts always get a higher ID than all the other posts so ordering it by “ID” is no option.

    Thread Starter thomas

    (@beloutte)

    ok I’ll try this in a couple of minutes

    but with my custom field as post ID it should have worked ? no ?

    edit: It works ! thanks a lot !

    Moderator keesiemeijer

    (@keesiemeijer)

    Glad you got it resolved.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘orderby=ID for posts doesn't work’ is closed to new replies.