Order Results with add_filter custom_field_weights on custom post results
-
Hi,
I’ve search and searched and am now very confused. I love the plugin but really need to get custom-post-type listings that have the custom field ‘goto_premium_listing’ ticked (it’s a true/false field) listed at the top of the results.
I thought the following would do it, but no luck.
add_filter('relevanssi_match', 'custom_field_weights'); function custom_field_weights($match) { $premium = get_post_meta($match->doc, 'goto_premium_listing ', true); if ('1' == $premium) { $match->weight = $match->weight * 2; } else { $match->weight = $match->weight / 2; } return $match; }
I’m not a power coder, so excuse me, but could this be something to do with the if (‘1’ == $premium) bit considering my custom field is a true/false or does ‘l’ mean true?
Does the custom_field_wights filter work with with custom fields on custom posts. I’m using the Custom Field Suite by Matt Gibbs to make the custom field on a custom post type ‘goto_listing’.
I have the goto_listing custom post type ticked in Relevanssi under ‘Choose taxonomies to index’.
Default order for results: is set to Post date.
All valid results show, but they’re still appearing by post date regardless of whether the custom field is ticked (true).
If this won’t work with custom fields applied to custom posts is there a way to weight by a specific taxonomy term?
I also have a custom taxonomy of ‘pts_feature_tax’ with term of ‘featured’ which is ticked if the custom post is a ‘Premium Listing’. I’m using the the plugin Post Type Spotlight by Linchpin to add this taxonomy to the custom post type ‘goto_listing’.
I tried the ‘Sorting by category’ and ‘Sorting by meta field or comment count’ solution on https://www.relevanssi.com/user-manual/relevanssi_hits_filter/ but couldn’t figure out how to alter it to my needs.
Really need to fix this asap as the site must launch tomorrow.
Thanks for any help you can give.
Cheers,
Tracy
- The topic ‘Order Results with add_filter custom_field_weights on custom post results’ is closed to new replies.