最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Sort by page information by Ascending Numbers

programmeradmin1浏览0评论

Basically I have a problem that I have details being pulled from advanced custom fields and I currently have them ordered by page title in ascending order.

However, instead of ordering them Ascending by Page Title, I would like to order them by my custom field: *educational_ranking*.

<?php query_posts('post_type=page&post_parent=2&posts_per_page=-1&orderby=&order=ASC'); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

<tr>
<td><?php echo the_field('educational_ranking'); ?></td>
<td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td>
<td><?php echo the_field('current_students'); ?></td>
<td>£<?php echo the_field('tuition_fees'); ?></td>
<td></td>
</tr>

<?php endwhile; rewind_posts(); ?>

Thats what I have so far, I cannot seem to work out how to sort by the field: 'educational_ranking' - any ideas?

Basically I have a problem that I have details being pulled from advanced custom fields and I currently have them ordered by page title in ascending order.

However, instead of ordering them Ascending by Page Title, I would like to order them by my custom field: *educational_ranking*.

<?php query_posts('post_type=page&post_parent=2&posts_per_page=-1&orderby=&order=ASC'); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

<tr>
<td><?php echo the_field('educational_ranking'); ?></td>
<td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td>
<td><?php echo the_field('current_students'); ?></td>
<td>£<?php echo the_field('tuition_fees'); ?></td>
<td></td>
</tr>

<?php endwhile; rewind_posts(); ?>

Thats what I have so far, I cannot seem to work out how to sort by the field: 'educational_ranking' - any ideas?

Share Improve this question asked Jul 30, 2012 at 11:26 Owen O'NeillOwen O'Neill 811 silver badge7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Use custom fields wp_query

Ex

<?php
    $args = array(
        'post_type' => 'page',
        'meta_query' => array(
            array(
                'key' => 'mytitle',
                'value' => 'title',                
                'orderby' => 'mytitle',
                'order' => 'DESC'
            ),           
        )
     );
    $query = new WP_Query( $args );
 if ( have_posts() ) while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>

<tr>
<td><?php echo the_field('educational_ranking'); ?></td>
<td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td>
<td><?php echo the_field('current_students'); ?></td>
<td>£<?php echo the_field('tuition_fees'); ?></td>
<td></td>
</tr>

<?php endwhile; rewind_posts(); ?>
发布评论

评论列表(0)

  1. 暂无评论