Skip to content

Instantly share code, notes, and snippets.

Created October 3, 2014 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/9a43f6e3e9c0ceb93655 to your computer and use it in GitHub Desktop.
Save anonymous/9a43f6e3e9c0ceb93655 to your computer and use it in GitHub Desktop.
//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