Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Forked from anonymous/Moomin
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/18a394053ab54aa1fecb to your computer and use it in GitHub Desktop.
Save jchristopher/18a394053ab54aa1fecb to your computer and use it in GitHub Desktop.
<?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