<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

function freshenup_get_yarpp_related_posts_array( $post_id ) {
    if ( ! function_exists( 'yarpp_get_related' ) ) {
        return array(); // YARPP not active
    }

    $post = get_post( $post_id );
    if ( ! $post ) {
        return array(); // Invalid post
    }

    $related_posts = yarpp_get_related(array(), $post_id);

    $results = array();

    if ( ! empty( $related_posts ) ) {
        foreach ( $related_posts as $related ) {
            $results[] = array(
                'title' => get_the_title( $related->ID ),
                'url'   => get_permalink( $related->ID ),
                'excerpt' => wp_strip_all_tags(get_the_excerpt( $related->ID ) )
            );
        }
    }

    return $results;
}

?>