• Resolved jorge2904

    (@jorge2904)


    Im trying to get a list of pages and order them by a value in one of my meta keys. This is my code….

    <?php
    query_posts('post_type=page&meta_key=front_page_nav&meta_value=true&orderby=&meta_key=front_page_nav_position');
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <li>
     <a href="<?php the_permalink()?>"><?php the_title()?></a>
    </li>
    <?php endwhile; endif; ?>

    In the query im getting a post thats a page has a value of true in the ‘front_page_nav’ and i want to order it by another meta key called ‘front_page_nav_position’. This query works until I add the order by.

    Any ideas

Viewing 2 replies - 1 through 2 (of 2 total)
  • According to the query_posts article

    orderby=meta_value – note that a meta_key=some value clause should be present in the query parameter also

    so you would need something like:

    query_posts('meta_key=front_page_nav_position&orderby=meta_value');

    Thread Starter jorge2904

    (@jorge2904)

    Ok in the end I used an array to give query_posts() parameters..

    $query = array(
     'post_type' => 'page',
     'meta_key' => array('front_page_nav', 'front_page_nav_position'),
     'meta_value' => array('true'),
     'order_by' => array('front_page_nav_position'),
     'order' => 'ASC'
    );
    query_posts($query);
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Ordering by meta key value’ is closed to new replies.