WordPress.org

Ready to get started?Download WordPress

Forums

change post order from by date to by meta key value (2 posts)

  1. offpeakdesign
    Member
    Posted 1 year ago #

    Hi,
    I'm trying to change the sort order of posts displayed in the archive/search page to sort by a meta key value. My meta key is 'work' and the value is numerical.

    I think I'm suppose to add the following code somewhere, but I'm not quite sure where's the best place to add it:
    $query = new WP_Query( array ( 'orderby' => 'meta_value', 'meta_key' => 'work' ) );

    I'm using a child theme.

    Any help will send waves of good karma your way.
    Thanks!

  2. potentweb
    Member
    Posted 1 year ago #

    http://codex.wordpress.org/Class_Reference/WP_Query

    You use it with the loop not the default loop. You have to use the while loop

Topic Closed

This topic has been closed to new replies.

About this Topic