[wp-trac] [WordPress Trac] #59064: WordPress AJAX Excerpt Length Issue 6.3
WordPress Trac
noreply at wordpress.org
Fri Aug 11 01:53:30 UTC 2023
#59064: WordPress AJAX Excerpt Length Issue 6.3
-------------------------------------------------+-------------------------
Reporter: wpcodeus | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting
| Review
Component: Posts, Post Types | Version: 6.3
Severity: major | Keywords: needs-
Focuses: javascript, coding-standards, php- | testing
compatibility |
-------------------------------------------------+-------------------------
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
<?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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59064>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list