Skip Navigation

[Resolved] Relevanssi sort by title not working in views but working in generic site search

This support ticket is created 6 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Christian Cox 6 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#1109080

I am trying to set search order by title by using the below code from Relevanssi:

add_filter('relevanssi_modify_wp_query', 'rlv_sort_by_title');
function rlv_sort_by_title($q) {
$q->set('orderby', 'post_title');
$q->set('order', 'asc');
return $q;
}

This is working on the normal search function in wordpress but when using the search function within a view it is not changing it to be ordered by title.

Link to a page where the issue can be seen:

Here is the generic search term: hidden link

Here is the views search term: hidden link

#1109111

Hi, can you tell me the "Ordering" settings for this View? Go to Toolset > Views and edit this View. If you cannot see the "ordering" settings, scroll to the top right corner of the page and click "Screen options". You can enable the Ordering options here. Try changing this to post_title, ascending.

If that does not change the sort order, add the cached="off" parameter to the View shortcode like this:

[wpv-view name="Your View name" cached="off"]

Let me know the results of these tests.

#1109292

I have tested turning off the cache but it is still not putting them in alphabetical order on search. The initial load is putting them in alphabetical order. I would like to know what I would have to do for the code that they provide to work with toolset?

#1109595

Sorry, I didn't get a clear response to this question and it is important:
can you tell me the "Ordering" settings for this View?

I also need to know if you temporarily remove the custom code, is the View sorted by post title as expected?

These two questions will help me determine how to use their custom code effectively with Views.

#1111452

Sorry I didn't explicitly reply to this because the other part of my answer also answered this. The ordering is set to by "post title" > "ascending" and this causes the page load to work correctly when initially loading the results. Then when you search they display in order of relevance. This is the default method with Relevannsi. But the code I have put above is supposed to fix that. In normal WordPress search (like whole site search results) the archive page with all my posts and custom post types, the results now appear in alphabetical order which is the desired effect, but the view results don't show in alphabetical order...

#1111695

Okay thanks, I ran some local tests and I'm not seeing the same problem with a basic View, so there must be something else going on.
- Is the search View using AJAX updates? Are the results sorted differently if change to or from AJAX updates?
- Are any other Query filters or search filters applied to the custom search View?
- Is the search results WordPress Archive using pagination? Please enable pagination with AJAX and tell me if the archive sort order is accurate after paginating.