Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active August 29, 2015 13:56
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/9329543 to your computer and use it in GitHub Desktop.
Save jchristopher/9329543 to your computer and use it in GitHub Desktop.
Index filenames for all images in galleries on the current page in SearchWP
<?php
function my_searchwp_extra_metadata( $extra_meta, $post_being_indexed ) {
// make sure there's a shortcode
if( has_shortcode( $post_being_indexed->post_content, 'gallery' ) ) {
$galleries = get_post_galleries_images( $post_being_indexed );
if( !empty( $galleries ) ) {
$all_gallery_images = array();
foreach( $galleries as $gallery ) {
foreach( $gallery as $image ) {
$all_gallery_images[] = $image;
}
}
$extra_meta['my_images'] = $all_gallery_images;
}
}
return $extra_meta;
}
add_filter( 'searchwp_extra_metadata', 'my_searchwp_extra_metadata', 10, 2 );
function my_searchwp_meta_keys( $keys ) {
// the keys we used to store author meta (see https://gist.github.com/jchristopher/8558947 for more info)
$my_custom_meta_keys = array(
'my_images'
);
// merge my custom meta keys with the existing keys
$keys = array_merge( $keys, $my_custom_meta_keys );
// make sure there aren't any duplicates
$keys = array_unique( $keys );
return $keys;
}
add_filter( 'searchwp_custom_field_keys', 'my_searchwp_meta_keys', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment