Home Forums Community Support Forum WordPress Plugins Orbisius Child Theme Creator Orderby parameter not working in WP_Query

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2726
    tplante
    Participant

    I have a Mexin Child Theme and I’m trying to order posts by a custom field. I have done this for many other websites without any issues, but can’t get it to work with this child theme. I also can’t get a simple ascending order to work, it all seems to be overridden and posts of any kind sort by post date (descending). Here is my code:

    $args = array(
    ‘post_type’ => ‘ocean-expeditions’,
    ‘orderby’ => ‘meta_value_num’,
    ‘meta_key’=> ‘year’
    );
    $the_query = new WP_Query($args);
    ?>
    <div class=”ocean-exp-wrap headlines-wrap”>

      <?php if (have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>

    • <div class=”blog-date-sec”>
      <span><?php the_field(‘month’); ?></span>
      <h3><?php the_field(‘year’); ?></h3>
      </div>
      <?php the_field(‘image’); ?>
      <h3>“><?php the_title(); ?></h3>
      <div class=”headline-description”>
      <?php echo custom_field_excerpt(); ?>
      </div>
      <p class=”read”>“>Read More →</p>
    • <hr>
      <?php endwhile; endif; ?>

    </div>

    I appreciate any and all help you can provide! Thanks!

    #2727
    Slavi Marinov
    Keymaster

    Hi,

    This is related to our plugin, however, you can find how to sort by meta value by going to this link:
    http://wordpress.stackexchange.com/questions/15477/custom-query-with-orderby-meta-value-of-custom-field

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.