AnsPress_Theme::get_the_excerpt( string $excerpt, object|null $post = null )

Description #

Generate question excerpt if there is not any already.

Parameters #

  • $excerpt
    string (Required) Default excerpt.
  • $post
    object | null (Optional) WP_Post object. Default value: null

Changelog #

VersionDescription
4.1.0Introduced.

Source #

File: includes/class-theme.php

	public static function get_the_excerpt( $excerpt, $post = null ) {
		$post = get_post( $post );

		if ( 'question' === $post->post_type ) {
			if ( get_query_var( 'answer_id' ) ) {
				$post = ap_get_post( get_query_var( 'answer_id' ) );
			}

			// Check if excerpt exists.
			if ( ! empty( $post->post_excerpt ) ) {
				return $post->post_excerpt;
			}

			$excerpt_length = apply_filters( 'excerpt_length', 55 );
			$excerpt_more   = apply_filters( 'excerpt_more', ' […]' );
			return wp_trim_words( $post->post_content, $excerpt_length, $excerpt_more );
		}

		return $excerpt;
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment