WordPress.org

Ready to get started?Download WordPress

Forums

WP_Query order by post meta numeric value (3 posts)

  1. Leo Blanchette
    Member
    Posted 1 year ago #

    Does WP_Query also check post_meta if needed? I need to order the posts by a numeric value of 1-3 in a post meta attribute, or possibly exclude from results if the value = 0.

    How is this built into WP_Query?

  2. amduffy
    Member
    Posted 1 year ago #

    query_posts(
        array(
                'order'     => 'ASC',
                'meta_key' => 'your_meta_key',
                'orderby'   => 'meta_value_num'
        )
    );
  3. Leo Blanchette
    Member
    Posted 1 year ago #

    I could not have figured out that on my own, period. Your awesome.

Topic Closed

This topic has been closed to new replies.

About this Topic