WordPress.org

Support

Support » Themes and Templates » How can I sort (orderby) my post by custom field value

How can I sort (orderby) my post by custom field value

  • dinesh786
    Member

    @dinesh786

    Hello friends,

    I have a custom post type “News”
    and with news I added a custom field “choose_date” (we want to give our own date instead of wp date )

    now I want to show post order by “choose_date” field
    than what should i do? any method or idea to do this?

    My current query arguments are
    $args = array(
    ‘post_type’=> ‘news’,
    ‘order’ => ‘DESC’,
    );

    what should I add in this?
    Please help me

    I used ‘orderby’ => ‘meta_value’, ‘meta_key’ => ‘choose_date’

    But its not giving in proper order

Viewing 2 replies - 1 through 2 (of 2 total)
  • dinesh786
    Member

    @dinesh786

    Ok, Its working fine,
    But the DB stored values in “Sep 27, 2012” format

    I used Custom field plugin and used Date Picker field type for choose_date field

    any solution to store date value in integer format?

    dinesh786
    Member

    @dinesh786

    Can I do filter values by query like:

    ‘meta_query’ => array(
    array(
    ‘key’ => ‘choose_date’,
    ‘value’ => date(“M d, Y”),
    )
    ),

    value stored in db in string date format, and i want to fetch order by date

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How can I sort (orderby) my post by custom field value’ is closed to new replies.