Skip to content

Instantly share code, notes, and snippets.

@msaari
Created January 22, 2019 04:06
Show Gist options
  • Save msaari/eede06d1b67ddba6197b3726b7426b29 to your computer and use it in GitHub Desktop.
Save msaari/eede06d1b67ddba6197b3726b7426b29 to your computer and use it in GitHub Desktop.
Flexible content relationship fields
<?php
add_filter( 'relevanssi_content_to_index', 'rlv_relationship_content', 10, 2 );
function rlv_relationship_content( $content, $post ) {
global $wpdb;
$relationships = unserialize( $wpdb->get_var( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key LIKE 'sidebar_groups_%_people'" ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions
if ( ! is_array( $relationships ) ) {
$relationships = array( $relationships );
}
foreach ( $relationships as $related_post_id ) {
$content .= ' ' . get_the_title( $related_post_id );
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment