Forums

[resolved] orderby=ID for posts doesn't work (6 posts)

  1. beloutte
    Member
    Posted 7 months ago #

    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 !

  2. keesiemeijer
    moderator
    Posted 7 months ago #

    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);
  3. beloutte
    Member
    Posted 7 months ago #

    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); ?>
  4. keesiemeijer
    moderator
    Posted 7 months ago #

    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.

  5. beloutte
    Member
    Posted 7 months ago #

    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 !

  6. keesiemeijer
    moderator
    Posted 7 months ago #

    Glad you got it resolved.

Reply

You must log in to post.

About this Topic