• Hi! I’m using custom fields to sort all my post o a custom page template. Everything works great until more than 5 posts are being displayed.

    The custom field i’m using is called “ordning”.

    Here’s the code:

    <ul class="indexbox">
    <?php $recent = new WP_Query("cat=0&showposts=0&orderby=meta_value&meta_key=ordning&order=DESC"); while($recent->have_posts()) : $recent->the_post();?>
    
    <li>
    <?php if ( get_post_meta($post->ID, 'thumb', true) ) : ?>
    <a href="<?php the_permalink(); ?>"><img src="lib/<?php echo get_post_meta($post->ID, 'thumb', true) ?>" /></a>
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    <?php if ( get_post_meta($post->ID, 'beskrivning', true) ) : ?><div class="beskrivning-display"><?php echo get_post_meta($post->ID, 'beskrivning', true) ?></div><?php endif; ?>
    <?php endif; ?>
    </li>
    
    <?php endwhile; ?>
    </ul>

    Any ideas what the problem could be? I’m using WordPress 3.1.1.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter kazie

    (@kazie)

    I should probably add that the 6th post is being displayed, but the posts custom field id is being ignored and displayed before the other 5 posts.

    Why do you have ‘cat=0’ in there? Are you trying to display a certain category only? If that is the case, then perhaps all posts are being picked up and some don’t have this custom field? If that’s the case then the posts with the custom field will be displayed first, in order, followed by the rest.

    Thread Starter kazie

    (@kazie)

    0 is the value for all categories right? I’m not using any categories so I changed it to 1 (for uncategorized) but the problem remains.

    Thread Starter kazie

    (@kazie)

    OK, so this apparently had nothing to do with the 6th post.

    This is how i sorted the posts before:

    1st post: ordning: 14
    2nd post: ordning: 13
    3rd post: ordning: 12
    4th post: ordning: 11
    5th post: ordning: 10
    6th post: ordning: 9
    7th post: ordning: 8

    The posts are being displayed in the correct order when i changed the custom fields to;

    1st post: ordning: 14
    2nd post: ordning: 13
    3rd post: ordning: 12
    4th post: ordning: 11
    5th post: ordning: 10
    6th post: ordning: 09
    7th post: ordning: 08

    It works I guess but the system seems kinda fragile.

    Ah, yes, that would do it – it’s because the data sored in the custom field is a string, not an integer.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom field order breaks after 5th post’ is closed to new replies.