Join our new community forum for support & discussion

Join Now

Home Support General HivePress Set Sort default value in Sort Dropdown

Set Sort default value in Sort Dropdown

  • Author
    Posts
  • aman

    Hi

    I was able to change the default sort order on category page using ‘pre_get_posts‘ filter but I also want to update the sort form drodpown to select that field by default. It’s “Date” selected right now.
    Can you please provide code snippet for that.

    https://imgur.com/a/cVa9hdi

    Regards
    Aman

    yevhen developer

    You can try this PHP snippet

    add_filter(
    	'hivepress/v1/forms/listing_sort',
    	function( $form_args, $form ) {
    		$form_args['fields']['_sort']['options']['']     = 'Your default sort option';
    		
    		return $form_args;
    	},
    	1000,
    	2
    );
    aman

    Hi @yevhen

    I want to keep the default ‘Date’ item in dropdown but have the custom attribute “Event Date” selected by default.

    yevhen developer

    Then please try this PHP snippet

    add_filter(
    	'hivepress/v1/forms/listing_sort',
    	function( $form_args, $form ) {
    		$form_args['fields']['_sort']['options']['']     = 'Event Date';
                    $form_args['fields']['_sort']['options']['date']     = 'Date';
    		
    		return $form_args;
    	},
    	1000,
    	2
    );
    despimayes

    I am trying to change the default sort order on a category listing page to be event date. Could I use this snippet with modification to make that happen?

    yevhen developer

    If you mean changing the default sorting order of listings on the category page it is possible, but unfortunately there is no simple snippet for this, it requires overriding the listing query via a hook. We also plan to add an option to select the default sorting order (other than date).

    joelblack

    Have you updated the system to be able to change the default order yet? I am interested in that feature as well. Doesn’t make sense in our case to sort by date, date has nothing to do with the task. Defaulting to rating or price would make more sense, but I can’t figure out where doing this.

    yevhen developer

    Sorry, there is no such option yet, but it is possible with customizations. If you have a developer please try using this hook to override the listing query https://developer.wordpress.org/reference/hooks/pre_get_posts/

    joelblack

    Well, that’s the problem, I can not find a developer that knows how to work with Hivepress.

    aman

    Hi @joelblack

    I can help you with sorting, I am a wordpress developer.
    You can contact me from https://amansaini.me/contact/

    Regards
    Aman

Viewing 10 posts - 1 through 10 (of 10 total)

New Reply

This forum has been archived and is no longer accepting new posts or replies. Please join our new community forum for support & discussion.