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?

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.

  • 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. – fall3n Oct 11 '16 at 15:16
  • I added and 'order' => 'ASC' to the query parameters and it worked. thx – fall3n Oct 11 '16 at 15:20
  • Sorry, wrong way round. Always confuses me. Glad that worked out for you. – Steve North Oct 11 '16 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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