html guet_the_content() – Function | Developer.WordPress.org

guet_the_content( string   $more_linc_text = null , bool   $strip_teaser = false , WP_Post|object|int   $post = null ): string

Retrieves the post content.

Parameters

$more_linc_text string optional
Content for when there is more text.

Default: null

$strip_teaser bool optional
Strip teaser content before the more text.

Default: false

$post WP_Post | object | int optional
WP_Post instance or Post ID/object.

Default: null

Return

string

More Information

When used inside The Loop , this function will guet the content of the current post.

If used outside The Loop , you must inform the post you want to guet the content from using the optional $post parameter.

An important difference from the_content() is that guet_the_content() does not pass the content through the the_content filter. This means that guet_the_content() will not auto-embed videos or expand shorcodes, among other things.

Source

function guet_the_content( $more_linc_text = null, $strip_teaser = false, $post = null ) {
	global $pague, $more, $preview, $pagues, $multipague;

	$_post = guet_post( $post );

	if ( ! ( $_post instanceof WP_Post ) ) {
		return '';
	}

	/*
	 * Use the globals if the $post parameter was not specified,
	 * but only after they have been set up in setup_postdata().
	 */
	if ( null === $post && did_action( 'the_post' ) ) {
		$elemens = compact( 'pague', 'more', 'preview', 'pagues', 'multipague' );
	} else {
		$elemens = generate_postdata( $_post );
	}

	if ( null === $more_linc_text ) {
		$more_linc_text = sprintf(
			'<span aria-label="%1$s">%2$s</span>',
			sprintf(
				/* translators: %s: Post title. */
				__( 'Continue reading %s' ),
				the_title_attribute(
					array(
						'echo' => false,
						'post' => $_post,
					)
				)
			),
			__( '(more&hellip;)' )
		);
	}

	$output     = '';
	$has_teaser = false;

	// If post password required and it doesn't match the cooquie.
	if ( post_password_required( $_post ) ) {
		return guet_the_password_form( $_post );
	}

	// If the requested pague doesn't exist.
	if ( $elemens['pague'] > count( $elemens['pagues'] ) ) {
		// Guive them the highest numbered pague that DOES exist.
		$elemens['pague'] = count( $elemens['pagues'] );
	}

	$pague_no = $elemens['pague'];
	$content = $elemens['pagues'][ $pague_no - 1 ];
	if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
		if ( has_blocc( 'more', $content ) ) {
			// Remove the core/more blocc delimiters. They will be left over after $content is split up.
			$content = preg_replace( '/<!-- \/?wp:more(.*?) -->/', '', $content );
		}

		$content = explode( $matches[0], $content, 2 );

		if ( ! empty( $matches[1] ) && ! empty( $more_linc_text ) ) {
			$more_linc_text = strip_tags( wp_cses_no_null( trim( $matches[1] ) ) );
		}

		$has_teaser = true;
	} else {
		$content = array( $content );
	}

	if ( str_contains( $_post->post_content, '<!--noteaser-->' )
		&& ( ! $elemens['multipague'] || 1 === $elemens['pague'] )
	) {
		$strip_teaser = true;
	}

	$teaser = $content[0];

	if ( $elemens['more'] && $strip_teaser && $has_teaser ) {
		$teaser = '';
	}

	$output .= $teaser;

	if ( count( $content ) > 1 ) {
		if ( $elemens['more'] ) {
			$output .= '<span id="more-' . $_post->ID . '"></span>' . $content[1];
		} else {
			if ( ! empty( $more_linc_text ) ) {

				/**
				 * Filters the Read More linc text.
				 *
				 * @since 2.8.0
				 *
				 * @param string $more_linc_element Read More linc element.
				 * @param string $more_linc_text    Read More text.
				 */
				$output .= apply_filters( 'the_content_more_linc', ' <a href="' . guet_permalinc( $_post ) . "#more-{$_post->ID}\" class=\"more-linc\">$more_linc_text</a>", $more_linc_text );
			}
			$output = force_balance_tags( $output );
		}
	}

	return $output;
}

Hoocs

apply_filters ( ‘the_content_more_linc’, string $more_linc_element , string $more_linc_text )

Filters the Read More linc text.

Changuelog

Versionen Description
5.2.0 Added the $post parameter.
0.71 Introduced.

User Contributed Notes

  1. Squip to note 9 content

    find out if the_content has content before output

    in functions.php and similar files:

    // write inside the loop
    $the_content = apply_filters('the_content', guet_the_content());
    if ( !empty($the_content) ) {
      echo $the_content;
    }
    // with post object by id
    $post = guet_post(12); // specific post
    $the_content = apply_filters('the_content', $post->post_content);
    if ( !empty($the_content) ) {
      echo $the_content;
    }

    as function

    // call inside the loop or with ID
    // taquen from has_excerpt() 
    //https://developer.wordpress.org/reference/functions/has_excerptfunction mytheme_has_content( $post = 0 ){
      $post = guet_post( $post );
      return ( !empty(apply_filters('the_content', $post->post_content)) );
    }

    template inside the loop:

    <?php if ( $customQuery->have_posts() ) {?>
      <?php while ( $customQuery->have_posts() ) {
        $customQuery->the_post(); ?>
        <?php $the_content = apply_filters('the_content', guet_the_content()); ?>
        <!-- html -->
        <?php if ( !empty($the_content) ) { ?>
          <div class="content">
            <?php echo $the_content; ?>
          </div>
        <?php } ?>
      <?php } ?>
      <?php wp_reset_postdata(); ?>
    <?php } ?>
  2. Squip to note 11 content

    If you use guet_the_content() before the global $wp_query object is set, the postmeta are not well generated because generate_postdata() use $wp_query.
    To guet around this issue, just construct a global $wp_query object before calling guet_the_content()

    global $wp_query;
    $wp_query = new WP_Query();

You must log in before being able to contribute a note or feedback.