-
-
Save jchristopher/18a394053ab54aa1fecb to your computer and use it in GitHub Desktop.
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
<?php | |
function my_searchwp_extra_metadata( $extra_meta, $post_being_indexed ) { | |
// index the author country | |
$author_country = get_field('my_countries', $post_being_indexed->post_author ); | |
// it's stored as an array so let's get the actual text | |
$author_country = is_array( $author_country ) && count( $author_country ) ? implode( ' ', $author_country ) : ''; | |
if ( ! empty ( $author_country ) ) { | |
$extra_meta['my_author_meta_country'] = $author_country; | |
} | |
return $extra_meta; | |
} | |
add_filter( 'searchwp_extra_metadata', 'my_searchwp_extra_metadata', 10, 2 ); | |
function my_searchwp_author_meta_keys( $keys ) | |
{ | |
// the keys we used to store author meta (see https://gist.github.com/jchristopher/8558947 for more info) | |
$my_custom_author_meta_keys = array( | |
'my_author_meta_country' | |
); | |
// merge my custom meta keys with the existing keys | |
$keys = array_merge( $keys, $my_custom_author_meta_keys ); | |
// make sure there aren't any duplicates | |
$keys = array_unique( $keys ); | |
return $keys; | |
} | |
add_filter( 'searchwp_custom_field_keys', 'my_searchwp_author_meta_keys', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment