Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Changing the Deafult order

Tagged: 

Viewing 10 posts - 1 through 10 (of 10 total)
  • Pascal Tatipata
    #207342

    Im tryin to change the order of my custom post archives to a custom order. I followed many wp manuals, but nothing seems to work.

    Then I realize that S&F is probally overiding the orderby function of the archives where the filter is added.

    Where and how can I change the default order of S&F?

    The deafult is date i think. The custom order is not a meta value and it isalso not listed in > S&F> Posts > Default Order:

    Thanks

    Trevor Moderator
    #207350

    What order do you need to be using?

    Pascal Tatipata
    #207366

    I want the archive to sort on ‘orderby’ => ‘post_views’. Based on this plugin: https://dfactory.eu/products/post-views-counter/

    Thanks!

    Trevor Moderator
    #207372

    It would require that the plugin you mention stores this data in a Post Meta key in the WP postmeta table. Do you know if it does that?

    Pascal Tatipata
    #207391

    No it does not stores a post meta or meta_key value. That is the other method some people use for sorting post views without a plugin using meta etc

    This plugin does creates a table wp_post_views though.
    But we used it on our old site. Like this:
    $query = new WP_Query(array(‘post_type’ => ‘download’, ‘orderby’ => ‘post_views’, ‘order’ => ‘DESC’));

    This simply will sort the default archive on most view posts.

    But on this page it is not working
    https://www.dl-sounds.com/member/downloads

    The downloads are sorted by date. No matter what we tried.

    Trevor Moderator
    #207393

    Ah. Then the only way to do this is to edit the query arguments passed to our plugin. Use this filter:

    https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments

    And make sure no sort order is actually set in our plugin.

    Pascal Tatipata
    #207512

    Ok,

    I added the next code to function.php

    function filter_function_name( $query_args, $sfid ) {
    	
    	//if search form ID = 225, the do something with this query
    	if($sfid==6178)
    	{
    		//modify $query_args here before returning it
    		$query_args['orderby'] = 'post_views';
    				
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 10, 2 );

    But now if I use the filter it is only showing 2 downloads:
    https://www.dl-sounds.com/member/downloads/?sort_order=name+asc&_sfm_bpm=0+1000

    without the filter it is working:
    https://www.dl-sounds.com/member/downloads

    I must be doing something wrong?

    Trevor Moderator
    #207516

    See this link:

    https://www.dl-sounds.com/member/downloads/?sort_order=name+asc

    The difference is that I removed the range values. This means that the other posts have no values for that range, and are thus excluded.

    Pascal Tatipata
    #207604

    It is more like it does not work with S&F order filter.

    If I change the default order of the archive to post views instead of date, it is setting all S&F filters to post views. But this is not the case with the standard date setting.

    Why is this? Should we code the core files of S&F? Is it possible to make it work then?

    Because we need this ‘most popular’ setting. It is essential for CRO & marketing etc.
    We need this for the time being.

    Trevor Moderator
    #207658

    In this URL:

    https://www.dl-sounds.com/member/downloads/?sort_order=name+asc&_sfm_bpm=0+1000

    you have sort by name enabled. Do you need sort by name AND by post count? Surely that would not work?

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

The forum ‘Search & Filter Pro’ is closed to new topics and replies.