• Resolved maduro-blanco

    (@maduro-blanco)


    Thanks for a great plugin.

    At the moment Relevanssi can be instructed to sort searches in order of post_date by using&orderby=post_date. However, I have a blog that uses two dating systems, namely, WordPress’s own post_date, and a custom field for the original published date, which is always shown under the post’s title even if the post_date has been updated. In most instances I can easily sort posts by this custom field value using &orderby=meta_value&meta_key=original_date. However, Relevanssi doesn’t seem to recognise this.

    Is there currently a way around this problem, or will you be able to make Relevanssi sort by custom field values in the future?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Well, I didn’t know this was possible, looks like this is a fairly new feature in WordPress. Why not, I think I can add it, I just have to think about how, as the sort is done using a simple object sort, I suppose I just need to add the meta values to the objects before sorting. I’ll have to see how it works.

    Thread Starter maduro-blanco

    (@maduro-blanco)

    Thanks for that.

    I think the ability to sort results by meta_key (custom field) has been around for some time, and it is normally just a case of passing the query to query_posts. e.g.

    query_posts($query_string . '&orderby=meta_value&meta_key=original_date&order=desc')

    But for some reason Relevanssi bypasses my query_post submissions–perhaps it is simply a case of priority, and Relevanssi runs its own query, overriding any passed through function.php, or some such thing.

    Thread Starter maduro-blanco

    (@maduro-blanco)

    But then, it handles &orderby=post_date without any problems.

    Plugin Author Mikko Saari

    (@msaari)

    Relevanssi can’t handle anything that it isn’t explicitly told how to handle, as it doesn’t use the WordPress query, but instead queries its own index.

    Thread Starter maduro-blanco

    (@maduro-blanco)

    I see what you’re saying, and Relevanssi is only hard-coded to handle either sorting by “relevance” or post_date. Maybe some kind of filter hook could be inserted so that a custom SQL query could override the existing Relevanssi ORDER BY, e.g. by specifying a return along the lines of –

    WHERE $wpdb->postmeta.meta_key = ‘original_date’
    ORDER BY $wpdb->postmeta.meta_value ASC|DESC

    or whatever the correct SQL is for the current purposes.

    Plugin Author Mikko Saari

    (@msaari)

    Except SQL has nothing to do with it, as Relevanssi is not sorting SQL results, but $post object arrays. So, in order to make meta value sort possible, I’ll have to first add the meta values to the $post objects, then it’s simple to add.

    Thread Starter maduro-blanco

    (@maduro-blanco)

    Ah, I understand now. I missed what you where saying earlier, that Relevanssi sorts its own list of $post objects internally. Well, I’ll keep my fingers crossed and hope you can “sort it all out”, as they say 🙂

    Has this feature been added yet? Sorting by meta value would be perfect for my website 🙂

    Plugin Author Mikko Saari

    (@msaari)

    You can use relevanssi_hits_filter to sort the results any way you want, you can see an example using the meta values in this comment thread on Relevanssi.com.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Sorting results by "meta_key" values’ is closed to new replies.