Make WordPress Core

Opened 7 months ago

Closed 7 months ago

Last modified 7 months ago

#59064 closed defect (bug) (duplicate)

WordPress AJAX Excerpt Length Issue 6.3

Reported by: wpcodeus's profile wpcodeus Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.3
Component: Posts, Post Types Keywords:
Focuses: javascript, coding-standards Cc:

Description

One of our plugins are utilizing the WordPress AJAX do_action( "wp_ajax_{$action}" ); function to create an archive and shortcode that loads a custom post type with AJAX and Infinity scroll.

With WordPress 6.3 we experienced a weird conflict with the built in the_excerpt() function where any post type that was loaded with AJAX, the defined excerpt length was ignored. Excerpt length works everywhere else besides with the use of AJAX.

Is this a known issue? In the meantime, we have added some logic to detect if AJAX is being used and defined the excerpt length using wp_trim_words();

Below is an example of our temporary fix:

<?php

// Check if it's an AJAX request
        if (defined('DOING_AJAX') && DOING_AJAX) {
            $excerpt = wp_trim_words(get_the_content(), (int) $asp_expect_length, '...');

            // Check if the read more link should be appended
            if (empty($asp_disable_read_more) && $post->post_type == 'sermons') {
                $excerpt .= sprintf(' <a class="asp-read-more" href="%1$s" target="%2$s">%3$s</a>',
                    get_permalink(get_the_ID()), $asp_target_control, __('read more', 'advanced-sermons'));
            }

        } else {
            $excerpt = get_the_excerpt();
        }

I thought we would report our issue incase this needs to be investigated further.

If you would like access to our github to review the code for troubleshooting please let me know.

Change History (2)

#1 @audrasjb
7 months ago

  • Keywords needs-testing removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Severity changed from major to normal
  • Status changed from new to closed

Hello, welcome to WordPress Core Trac and thanks for the report,

We are already tracking this issue in #59043.

Thanks!

#2 @jrf
7 months ago

  • Focuses php-compatibility removed
Note: See TracTickets for help on using tickets.