0

I wrote a query:

WP_Query(array('post_type'=>'portfolio_item', 'post_status'=>'publish', 'posts_per_page'=>-5));

which works and does what I want except it sorts the results from oldest to newest, and I want them to appear newest to oldest. What can I add to the query parameters to make this happen?

1 Answer 1

2
WP_Query(array('post_type'=>'portfolio_item', 'post_status'=>'publish', 'posts_per_page'=>-5, 'order' => 'ASC'));

See: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

for order parameters.

Hope that helps.

3
  • that seems like exactly what I am looking for so I don't know why it didnt work. I tried 'order' => 'DESC' and its of them changed anything. The widget containing the query is still printing the portfolio_items starting from the beginning.
    – brothman01
    Commented Oct 11, 2016 at 15:16
  • I added and 'order' => 'ASC' to the query parameters and it worked. thx
    – brothman01
    Commented Oct 11, 2016 at 15:20
  • Sorry, wrong way round. Always confuses me. Glad that worked out for you.
    – Tex0gen
    Commented Oct 11, 2016 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.