WordPress.org

Ready to get started?Download WordPress

Forums

Ultimate WP Query Search Filter
Multiple Sort by Options (6 posts)

  1. Dootie Fresh
    Member
    Posted 7 months ago #

    Hello,

    Is it possible to have multiple sorting options available on the search form based on custom post meta?

    I see you can set a single sort option, I'm looking to have multiple options on the form so users can sort their results based on meta values for example check boxes next to the search button;
    Price: low to high, Price: high to low, Year: low to high, Year: high to low?

    Thanks

    http://wordpress.org/plugins/ultimate-wp-query-search-filter/

  2. TC.K
    Member
    Plugin Author

    Posted 7 months ago #

    Yes, it is possible with the some hooks. But it is rather complicated.

    Basically, you can add the extra sorting by using uwpqsf_form_bottom filter, and using uwpqsf_deftemp_query filter (for default search template) or uwpqsf_query_args to inject it into the search query.

  3. csumrell
    Member
    Posted 5 months ago #

    How can I add the ASC and DSC order by date checkboxes to the Search Form on the page. I have the checkboxes there on the form, but how do I inject that input into the ajax search query?

  4. TC.K
    Member
    Plugin Author

    Posted 5 months ago #

    You can inject it by using uwpqsf_query_args.

    For eg.

    add_filter('uwpqsf_query_args','injecting_custom_arg','',4);
    function injecting_custom_arg($args, $id,$getdata){
      //$getdata is the data from the form input. Using it like GET url parameter
     $args['orderby'] = $getdata['orderby_name']; //if orderby_name is your input name.
     $args['order'] = $getdata['sort'];//likewise sort is the name of the order input.
     return $args;
    }
  5. csumrell
    Member
    Posted 5 months ago #

    Thank you for the help.

    This is the code I ended up using to add two buttons: Sort By Newest and Sort By Oldest, that filter results by date to the search filter.

    add_filter('uwpqsf_form_bottom','injecting_buttons','',4);
    function injecting_buttons(){
    echo '<label><input '.$desc.' type="radio" id="taxhide" name="date" value="DESC"/>'.__("Sort By Newest","UWPQSF").'</label>';
    echo '<label><input '.$asc.' type="radio" id="taxhide" name="date" value="ASC"/>'.__("Sort By Oldest","UWPQSF").'</label>
    ';
    }

    add_filter('uwpqsf_query_args','injecting_custom_arg','',4);
    function injecting_custom_arg($args, $id,$getdata){
    $args['order'] = $getdata['date'];//likewise sort is the name of the order input.

    return $args;
    }

  6. Umakant Sonwani
    Member
    Posted 1 month ago #

    Hi Csumrell,
    How call this filter function in my custom page ,

    ///////////////////////////////////////////////////////

    add_filter('uwpqsf_form_bottom','injecting_buttons','',4);
    function injecting_buttons(){
    echo '<label><input '.$desc.' type="radio" id="taxhide" name="date" value="DESC"/>'.__("Sort By Newest","UWPQSF").'</label>';
    echo '<label><input '.$asc.' type="radio" id="taxhide" name="date" value="ASC"/>'.__("Sort By Oldest","UWPQSF").'</label>
    ';
    }

    add_filter('uwpqsf_query_args','injecting_custom_arg','',4);
    function injecting_custom_arg($args, $id,$getdata){
    $args['order'] = $getdata['date'];//likewise sort is the name of the order input.

    return $args;
    }

    //////////////////////////////////////////////////////////
    Thanks,

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.