esc_html__( 'Show related posts using ElasticPress. This widget will only appear on single post, page, and custom type pages.', 'elasticpress' ), 'show_instance_in_rest' => true, ); parent::__construct( 'ep-related-posts', esc_html__( 'ElasticPress - Related Posts', 'elasticpress' ), $options ); } /** * Display widget * * @param array $args Widget arguments * @param array $instance Widget instance variables * @since 2.2 */ public function widget( $args, $instance ) { if ( ! is_single() ) { return; } $related_posts = get_transient( 'ep_related_posts_' . get_the_ID() ); if ( false === $related_posts ) { $related_posts = Features::factory()->get_registered_feature( 'related_posts' )->find_related( get_the_ID(), $instance['num_posts'] ); if ( empty( $related_posts ) ) { if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) { set_transient( 'ep_related_posts_' . get_the_ID(), '', HOUR_IN_SECONDS ); // Let's not spam } return; } ob_start(); echo wp_kses_post( $args['before_widget'] ); if ( ! empty( $instance['title'] ) ) { echo wp_kses_post( $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'] ); } ?>