Created
October 3, 2014 14:37
-
-
Save anonymous/9a43f6e3e9c0ceb93655 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
//Basically just copy+pasted your code and changed the field name to "my_countries" which it's called in AFC | |
unction my_searchwp_extra_metadata( $extra_meta, $post_being_indexed ) { | |
// available author meta: http://codex.wordpress.org/Function_Reference/get_the_author_meta | |
// retrieve the author's name(s) | |
$author_country = get_field('my_countries', $post_being_indexed->post_author ); | |
// index the author name and bio with each post | |
$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 ); | |
//Var_dump | |
array(3) { [0]=> string(7) "Belarus" [1]=> string(5) "Italy" [2]=> string(5) "Japan" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment