algolia / algoliasearch-wordpress

❌🗑🙅‍♂️ Algolia Search plugin for WordPress is no longer supported. Please use our API client guide instead
https://www.algolia.com/doc/integration/wordpress/getting-started/quick-start/
GNU General Public License v2.0
358 stars 114 forks source link

How to change custom ranking? #792

Open jack-pallot opened 6 years ago

jack-pallot commented 6 years ago

What did you expect to happen?

WordPress re-indexing overwrites any values set in Algolia, so I need to set a custom ranking from within Wordpress. I have data available in wp_searchable_posts called 'priority', which needs to dictate the order in which posts appear as the top ranking factor.

What happened instead?

Nothing. When I refresh the Algolia indicies section, nothing has changed.

How can we reproduce this behavior?

The code below is what I'm trying to use. Is this the correct way to do this?

<?php
  function custom_post_ranking( array $settings ) {
    $custom_ranking = $settings['customRanking'];
    array_unshift( $custom_ranking, 'desc(priority)' );
    $settings['customRanking'] = $custom_ranking;
    return $settings;
  }

  add_filter( 'algolia_wp_searchable_posts_index_settings', 'custom_post_ranking' );
?>

Technical info