Hi,
I used a function that I pasted on the functions.php just as you recomended:
add_filter( 'related_posts_by_taxonomy', 'rpbt_add_title_filter', 10, 4 );
function rpbt_add_title_filter( $results, $post_id, $taxonomies, $args ) {
global $rpbt_related_args;
if ( isset( $args['type'] ) && ( 'shortcode' === $args['type'] ) ) {
$names_args = array(
'include' => $args['related_terms'],
'fields' => 'id=>name',
);
// Get the term names for the related terms used in the query;
$terms = get_terms( $taxonomies, $names_args );
$rpbt_related_args = $args;
$rpbt_related_args['term_names'] = $terms;
$rpbt_related_args['taxonomies'] = $taxonomies;
// Add a filter to the title for the shortcode.
add_filter( 'the_title', 'rpbt_add_terms_to_title', 10, 2 );
// Remove the filter after displaying related posts.
add_filter( 'related_posts_by_taxonomy_after_display', 'rpbt_remove_filter' );
}
return $results;
}
function rpbt_add_terms_to_title( $title, $id ) {
global $rpbt_related_args;
// Get the terms for the current post ID
$terms = wp_get_object_terms( $id, array_map( 'trim', (array) $rpbt_related_args['taxonomies'] ), array( 'fields' => 'ids' ) );
// Remove terms not assigned to current post ID.
$terms = array_values( array_intersect( $rpbt_related_args['related_terms'], $terms ) );
$names = '';
// Create term names string
if ( $terms ) {
foreach ( $terms as $term ) {
if ( isset( $rpbt_related_args['term_names'][$term] ) ) {
$names .= $rpbt_related_args['term_names'][$term] . ', ';
}
}
$names = trim( $names, ', ' );
$names = !empty( $names ) ? ' ' . $names . '' : '';
}
return $names . $title ;
}
// Remove the filter
function rpbt_remove_filter() {
remove_filter( 'rpbt_add_terms_to_title','the_title', 10, 2 );
}
But I get the taxonomy and the title on the same html label so I can’t style them diferent. Also they are in the same line.
Thanks for the help with the images by the way, it worked perfect ??