Title: Ordering posts by custom fields
Last modified: August 24, 2016

---

# Ordering posts by custom fields

 *  [arturocivit](https://wordpress.org/support/users/arturocivit/)
 * (@arturocivit)
 * [11 years ago](https://wordpress.org/support/topic/ordering-posts-by-custom-fields/)
 * good day, quick question, I have a site that pulls posts from certain category,
   basically the code to see how I call those posts is as follows:
 *     ```
       <div class="jumbotron">
       <h2>Ultimos Estrenos Nintendo Wii</h2>
       <?php query_posts('cat=99&order=DSC&showposts=11&paged='.get_query_var('paged')); ?>
       <?php if (have_posts()) :  ?>
       <?php while (have_posts()) : the_post(); ?>
       <a href="<?php echo get_permalink(); ?>"><?php the_post_thumbnail( 'thumb-small' ); ?></a>
       <?php endwhile; ?>
       <?php else: ?>
       <p><?php _e('No posts were found. Sorry!'); ?></p>
       <?php endif; ?></p>
       <br /><br />
       <a href="http://bluegames.com.ve/category/nintendo-wii/" class="btn btn-xs btn-warning">VER TODOS LOS ESTRENOS</a>
       </div>
       ```
   
 * As you can see I’m using order=DSC to order posts but the client has a custom
   field that is a code, they want to order those posts using that custom field,
   but I’m not sure how to achieve that, I call that custom field using this:
 * `<?php echo get_post_meta($post->ID, 'Codigo de Pelicula', true); ?>`
 * But I don’t know how to order those posts using that custom field, so, asking,
   someone with that kind of past experience that can help with?

Viewing 1 replies (of 1 total)

 *  [John Parris](https://wordpress.org/support/users/mindctrl/)
 * (@mindctrl)
 * [11 years ago](https://wordpress.org/support/topic/ordering-posts-by-custom-fields/#post-6077177)
 * Hi,
    As noted on the `query_posts` page, it’s not meant to be used by plugins
   or themes. ([http://cl.ly/image/1e1W0V1J1A2b](http://cl.ly/image/1e1W0V1J1A2b))
   It’s best to WP_Query.
 * See this documentation for querying posts based on custom fields.
    [http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters](http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters)

Viewing 1 replies (of 1 total)

The topic ‘Ordering posts by custom fields’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [John Parris](https://wordpress.org/support/users/mindctrl/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/ordering-posts-by-custom-fields/#post-6077177)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
