Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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(); ?>
share|improve this answer
    
I am not to sure on how to do this? How would I do this different to what I have done above? –  Owen O'Neill Jul 30 '12 at 12:00
    
@OwenO'Neill What is the key of your custom field(for which you want to short) ? –  Ajay Patel Jul 30 '12 at 12:13
    
what do you mean by Key? The one I want is 'educational_ranking' - hope that helps!? –  Owen O'Neill Jul 30 '12 at 15:38
    
is there a chance that you can help? –  Owen O'Neill Aug 1 '12 at 9:15
    
ACF(Advanced Custom Fields) i think typically stores prefixed keys(to hide them from the WP UI), try prefixing the custom field key with _ when you query by it, eg. key => '_your_field'. –  t31os May 12 '13 at 3:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.