在自定义字段上排序

时间:2012-04-25 10:10:36

标签: sql wordpress sql-order-by

我需要您的帮助我的WordPress小部件类型代码。我有一个名为ordermetakey的自定义字段。我需要在下面的框中对此自定义字段ASC上的帖子进行排序。它是一个数字timestamp

<div class="list-block">
    <ul>
       <?php $postslist = get_posts('numberposts=5'); foreach ($postslist as $post) : setup_postdata($post); ?>
       <li>
          <p><strong><a title="Post: <?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></strong><br \> <span><?php echo get_post_meta($post->ID, 'standplaats', true); ?></span></p>
       </li>
  <?php endforeach; ?>
    </ul>
</div>

1 个答案:

答案 0 :(得分:0)

<div class="list-block">
    <ul>
        <?php $postslist = get_posts( array(
            'meta_key' => 'ordermetakey',
            'orderby' => 'meta_value_num',
            'order' => 'ASC',
            'posts_per_page' => 5
        );
        foreach ($postslist as $post) : setup_postdata($post); ?>
        <li>
            <p><strong><a title="Post: <?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></strong><br \> <span><?php echo get_post_meta($post->ID, 'standplaats', true); ?></span></p>
        </li>
        <?php endforeach; ?>
    </ul>
</div>