0

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?

  • See Codex: WP_Query - Custom Field Parameters. And always add all relevant code to the question, instead of linking to a external resource. – Nicolai Apr 29 '15 at 13:30
  • Please add your code to your question. Most users will simply skip your post as it is really annoying and time wasting having to open multiple screens o read just one post :-) – Pieter Goosen Apr 29 '15 at 14:49
0

This is a code I'm using ina website that I'm creating for a client. Maybe it can point you in the right direction:

$current_date = date('Y-m-d');
$args = array(  
    'post_type' => 'billboard_evento',
    'posts_per_page' => 4,                            
    'meta_key' => 'fecha-inicio', //Declaring wich meta key I want to use
    'orderby' => 'fecha-inicio', //Ordering the queried elements by meta value 
    'order'  => 'ASC',

    'meta_query' => array(  //Querying by meta field
        array(
            'key' => 'fecha-inicio', //meta field name for an event start date
            'value' => $current_date, // Setting the value to current date
            'compare' => '>=', // Comparing current date with event start date
            'type' => 'DATE', //Type of value
        ),
    )
); 
$query_eventos = new WP_query($args);
  • Hola Eduardo gracias, the thing is, I'm trying to add that code to my call, here's what I am using: – Arturo May 7 '15 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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