• Resolved web-girl

    (@web-girl)


    Hello,

    I am looking for help writing a custom query for a meta field. I am creating a page of authors by category/year, and need to sort by last name, first name (using the custom field wpcf-sortname).

    I have tried to piece together information from old threads and this WordPress Codex page, Displaying Posts Using a Custom Select Query, but my SQL is weak. I am using the Types plugin to create a custom field and already tried to get help from the plugin section to no avail.

    Upon further reading, it seems like I can’t retrieve and sort by meta field using my existing query.

    Any help would be greatly appreciated ??

    <!-- Cooking from the current year -->
        <h3>Cooking</h3>
    	<?php query_posts(array('category__and'=>array(48,49),'meta_key'=>wpcf-sortname,'orderby'=>meta_value,'order'=>ASC,'posts_per_page'=>-1));
    
    if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
        <a href="<?php the_permalink() ?>" class="participants"><?php the_title(); ?></a><br />
        <?php endwhile; // end of the loop. ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Help Writing a Custom Query to Sort By Meta Field’ is closed to new replies.