• With Kadence theme, I have an endless loop on the search page.

    \WPFTS_Core::GetShortcodesContent is executed inside of get_the_excerpt filter. Calling the_content() here executes the_content hook and created an endless loop.

    I have fixed the problem with the following mu-plugin.

    
    /**
     * Save and remove the_content hooks.
     *
     * @param string  $post_excerpt Post excerpt.
     * @param WP_Post $post         Post.
     *
     * @return mixed
     */
    function fix_wpftps_before_get_the_excerpt( $post_excerpt, $post ) {
    	global $fix_wpftps_saved_the_content_hooks;
    
    	$fix_wpftps_saved_the_content_hooks = $GLOBALS['wp_filter']['the_content'];
    	unset( $GLOBALS['wp_filter']['the_content'] );
    
    	return $post_excerpt;
    }
    
    add_filter( 'get_the_excerpt', 'fix_wpftps_before_get_the_excerpt', - PHP_INT_MAX, 2 );
    
    /**
     * Restore the_content hooks.
     *
     * @param string  $post_excerpt Post excerpt.
     * @param WP_Post $post         Post.
     *
     * @return mixed
     */
    function fix_wpftps_after_get_the_excerpt( $post_excerpt, $post ) {
    	global $fix_wpftps_saved_the_content_hooks;
    
    	// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
    	$GLOBALS['wp_filter']['the_content'] = $fix_wpftps_saved_the_content_hooks;
    
    	return $post_excerpt;
    }
    
    add_filter( 'get_the_excerpt', 'fix_wpftps_after_get_the_excerpt', PHP_INT_MAX, 2 );
    

    In the plugin code, in \WPFTS_Core::GetShortcodesContent, it can be fixed by replacing

    
    				ob_start();
    				the_content();
    				$r = ob_get_clean();
    

    by

    
    				$r = get_the_content();
    

    Could you fix it? Thank you.

    • This topic was modified 2 years, 3 months ago by kaggdesign.
    • This topic was modified 2 years, 3 months ago by kaggdesign.
  • The topic ‘Endless loop in getting excerpt’ is closed to new replies.