• hello dear,
    am using custom post type, custom taxonomies, and 2 meta value : carprice , carmilieage
    after searching, i need to sort result by price / milieage
    but i wish if can i have drop down, with string
    &orderby=carprice&order=asc
    can anyone send me tutorial link or code ? thanks

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    I can’t direct you to any tutorials or offer any code, but I can outline the the general process. Perhaps you will have more luck finding information about the various parts in isolation and then be able to piece together a complete solution.

    You can add a drop down to the search form by hooking into the ‘get_search_form’ filter. If needed, you could setup your filter callback to only add the drop down when search results are being displayed.

    In order to actually affect the sort field and order, hook into the ‘pre_get_posts’ action and check query variables to determine if the query is to get search results. If so add or change query variables so the desired query is fashioned. Query variables are very similar to custom WP_Query arguments.

    In case your needs cannot be met by setting query variables, you can also alter the actual query string by using various ‘posts_*’ filters, in your case probably ‘posts_orderby’ and possibly ‘posts_join_paged’.

    I believe you’ll have an easier time finding information on these specific tasks rather than the complete process.

Viewing 1 replies (of 1 total)
  • The topic ‘tutorial needed’ is closed to new replies.