Inpsyde\MultilingualPress\Relations\Post\Search\RequestAwareSearch::get_posts PHP Метод

get_posts() публичный Метод

Returns the latest/best-matching posts with respect to the given context.
С версии: 3.0.0
public get_posts ( RelationshipContext $context ) : WP_Pos\WP_Post[]
$context Inpsyde\MultilingualPress\Relations\Post\RelationshipContext Relationship context data object.
Результат WP_Pos\WP_Post[] The latest/best-matching posts.
    public function get_posts(RelationshipContext $context)
    {
        $remote_site_id = $context->remote_site_id();
        if (!$remote_site_id) {
            return [];
        }
        $source_post = $context->source_post();
        if (!$source_post) {
            return [];
        }
        $args = ['numberposts' => 10, 'post_type' => $source_post->post_type, 'post_status' => ['draft', 'future', 'private', 'publish']];
        $remote_post_id = $context->remote_post_id();
        if ($remote_post_id) {
            $args['exclude'] = $remote_post_id;
        }
        $search_query = $this->get_search_query();
        if ($search_query) {
            $args = array_merge($args, ['s' => $search_query, 'orderby' => 'relevance']);
        }
        switch_to_blog($remote_site_id);
        $posts = get_posts($args);
        restore_current_blog();
        return $posts;
    }