Forums

Can someone help with this SQL query (4 posts)

  1. Johnny T
    Member
    Posted 2 years ago #

    $params=array(
    'showposts'=>2,
    'post_status' => 'publish,pending',
    'meta_key'=>'_needed',
    'meta_value'=>'true'
    );
    $query = new WP_Query;
    $my_results = $query->query($params);

    Hi all,
    I have the above query which selects 2 posts from my database that have the meta_key "_needed" set to "true".

    I want to ORDER the results by another field of meta data. So what I want is to say:

    $params=array(
    'showposts'=>2,
    'post_status' => 'publish,pending',
    'meta_key'=>'_needed',
    'meta_value'=>'true'
    ORDER BY
    'meta_key'=>'_date'
    );
    $query = new WP_Query;
    $my_results = $query->query($params);

    Is this possible??

    Or can I select ALL with 1 query and then Order the results with another query?

    Any ideas how I can achieve this??

    Many thanks for any help you can give me.

    Cheers

    John ;-)

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    orderby=meta_value

    Orderby Parameters

  3. Johnny T
    Member
    Posted 2 years ago #

    Hi MichaelH

    Thanks for your reply and your link. Is it possible to order by ANY meta value then? For instance could I do the following...

    $params=array(
    'showposts'=>2,
    'post_status' => 'publish,pending',
    'meta_key'=>'_needed',
    'meta_value'=>'true',
    'meta_key'=>'THE_KEY_I_WANT_TO_ORDER_BY',
    orderby=meta_value
    );
    $query = new WP_Query;
    $my_results = $query->query($params);

    ???

    Thanks for your support ;-)

  4. MichaelH
    Volunteer
    Posted 2 years ago #

    That may not answer your question...per the docs:

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

    That may not answer your question...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.