[wp-trac] [WordPress Trac] #59702: Excerpt filters does not work in Ajax calls

WordPress Trac noreply at wordpress.org
Tue Nov 14 18:42:05 UTC 2023


#59702: Excerpt filters does not work in Ajax calls
-------------------------------------+-------------------------------------
 Reporter:  villamzr                 |       Owner:  (none)
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  Awaiting Review
Component:  Themes                   |     Version:  6.3.2
 Severity:  critical                 |  Resolution:
 Keywords:  changes-requested        |     Focuses:  template, coding-
  reporter-feedback                  |  standards
-------------------------------------+-------------------------------------

Comment (by rebelord):

 6.4.1 here and not fixed.
 Here is a jQuery hotfix ex-post for anyone looking for it. To be used in
 {{{
 $.post( MyAjax.ajaxurl, formdata, function( response ){}
 }}}



 {{{
  /* hotfix for  excerpts length fail in Ajax -
 https://core.trac.wordpress.org/ticket/59702 */
           let excerpts=$(response).find(".your_excerpt_parent_class p");
           excerpts.each(function(){
                 let excerpt=$(this).html();
                 let new_excerpt = excerpt.split(" ").splice(0, 20).join("
 "); /* 20 is the count of words needed */
                 excerpt=excerpt.replace("“", "“"); /*these entities
 are present in the ajax output*/
                 excerpt=excerpt.replace("”", "”");
                 response=response.replace(excerpt, new_excerpt + "
 [...]");
           });
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59702#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list