Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to add sorting but don't have any idea how ot go about it. I would like to be able to sort by:

Date, Title, Price (custom field), Comments, Views, ASC + DESC

What would be the best way to do something like this?

share|improve this question
    
Check if this could help you - wordpress.stackexchange.com/q/57850/17968 –  amit Aug 19 '12 at 15:43
    
can you paste more information like the loop of the page / post where you want to add sorting –  Sagive SEO Aug 19 '12 at 16:53
    
@SagiveSEO like what? –  Joe Bobby Aug 19 '12 at 17:31
    
@amit i tried site.com/?orderby=title&order=dsc and it went the the blog page and sorted.. this is a custom post type how do i get it to sort on the same page? –  Joe Bobby Aug 19 '12 at 17:37
    
you can pass an extra parameter post_type, See my answer below –  amit Aug 19 '12 at 18:45
add comment

1 Answer

up vote 0 down vote accepted

Extending this answer for custom post type support.

For a custom post type you can pass an extra parameter ( post_type ) to url, example -

www.example.com/?post_type=FOO&orderby=title&order=dsc

Note - If you've specified some url rewrite for that post type then the above url will become something like this but still showing all posts of post type FOO with descending order by title.

www.example.com/FOO/?&orderby=title&order=dsc
share|improve this answer
    
this works, but is there any php I can add for sorting? I only got it to work by trying <a href="http://site.com/?post_type=portfolio&orderby=title&order=dsc">test</a> –  Joe Bobby Aug 19 '12 at 22:05
    
I didn't get you ? Do you want get this done without using url parameters ? I think this is best way to make posts sortable using a click. –  amit Aug 19 '12 at 22:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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