Last active
August 21, 2024 23:48
-
-
Save ajskelton/7ab9dacf39eda75aee5e06c2e40d7683 to your computer and use it in GitHub Desktop.
Add 'searchwp_related_sample_engines' filter to the get_samples function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get associative array of sample results for keywords | |
* | |
* @param string $existing_keywords | |
* | |
* @param int $post_id | |
* | |
* @return array | |
*/ | |
public function get_samples( $existing_keywords = '', $post_id = 0 ) { | |
$samples = array(); | |
$engines = \SearchWP\Settings::get_engines(); | |
if ( empty( $engines ) ) { | |
return $samples; | |
} | |
$engines = apply_filters( 'searchwp_related_sample_engines', $engines, $post_id ); | |
foreach ( $engines as $engine => $engine_settings ) { | |
$post_data = $this->related->get( array( | |
'engine' => $engine, | |
's' => $existing_keywords, | |
'post__not_in' => array( $post_id ), | |
), $post_id ); | |
if ( ! empty( $post_data ) ) { | |
foreach ( $post_data as $key => $val ) { | |
$val = absint( $val ); | |
$post_data[ $key ] = array( | |
'ID' => $val, | |
'post_title' => get_the_title( $val ), | |
'permalink' => get_permalink( $val ), | |
'post_type' => get_post_type( $val ), | |
); | |
} | |
} | |
$samples[] = array( | |
'engine' => array( | |
'name' => $engine, | |
'label' => $engine_settings->get_label(), | |
), | |
'samples' => empty( $post_data ) ? array() : $post_data, | |
); | |
} | |
return $samples; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment