1

We've got two channel, Images and Videos, that we're combining in search results. Searching by keyword works great. So does sorting by entry_date and title. But we'd also like to sort by other fields.

To simplify things, imagine a custom field in each channel - video_score, image_score - that hold integers received from elsewhere. So, how would it be possible to combine these two for the orderby?

If it's easier we can create fields video_order and image_order with unique ordering numbers, but due to the custom fields being in two channels I don't see how to use the same custom field name, which appears to be what we need for orderby.

Do we maybe need to hijack a core field?

Thanks, Paul

1

One way to do this would be to create a custom extension that uses the low_search_post_search hook. That will give you an array containing all parameters that will be passed through to the native channel:entries tag for parsing the results. That includes the entry_id or fixed_order parameter which contains the entry IDs for the search results (as long as a LS filter has been triggered).

With that list of IDs, you can query the DB for the values you want to sort by, and then re-sort the entry IDs based on those values. If you then set the fixed_order param with the newly sorted list, the search results should appear in the desired order.

Another way would be to create a fieldtype that hijacks a core field (as you suggested) like view_count_one to four.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.