Navigation überspringen

[Gelöst] Shortcode is not renderd after filtering

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:

I have a "Show More" shortcode that works on page load, but after filtering a Toolset View with AJAX the shortcode stops working because the replaced HTML loses its initialization.

Solution:

Wrap the Show-More initialization in a function and call it both on page load and again after Toolset’s AJAX events (js_event_wpv_parametric_search_results_updated and js_event_wpv_pagination_completed). Add this script in the View’s JS editor or your theme’s JS file so the Show-More feature re-initializes whenever the results refresh.

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/adding-custom-javascript-code-to-views-that-use-ajax/

This support ticket is created vor 2 weeks, 1 days. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Dieses Thema enthält 1 reply, hat 1 Stimme.

Zuletzt aktualisiert von Christopher Amirian vor 2 weeks, 1 days.

Assistiert von: Christopher Amirian.

Author
Artikel
#2820123

versteckter Link
Opleidingsdag Typ10 has a Show More shortcode which renders fine upon page load, but after filtering "onderwijsprofessionals en ondersteuners" the shortcode no longer works.

Is there a way to delay or run the Toolset script later so it does not interfere with the shortcode?

#2820144

Christopher Amirian
Unterstützer

Sprachen: Englisch (English )

Hi,

Welcome to Toolset support. You don’t need to “delay” Toolset; you just need to re-run your Show-More JS after the View finishes its AJAX refresh. Views replaces the results’ HTML on every filter change, so any JS that was bound on page-load must be re-initialized on the new markup.

Toolset exposes front-end events for exactly this. Use them to call your Show-More init again:

1. Put your Show-More initialization in a function you can call more than once (example name here; replace with your plugin’s init code):

// Put this in a JS file or in the View's JS editor
window.hlcInitShowMore = function () {
  // re-bind or (re)initialize your Show More behaviour here
  // e.g. $('.show-more').showMore({...});
};

2- Call it on first load and after Toolset updates the results:

jQuery(function($){
  // initial page load
  if (window.hlcInitShowMore) { window.hlcInitShowMore(); }

  // after a search or pagination AJAX completes for this View
  $(document).on(
    'js_event_wpv_parametric_search_results_updated js_event_wpv_pagination_completed',
    function(event, data){
      // optional: restrict to a specific View
      // if (data.view_unique_id !== 'YOUR_VIEW_UNIQUE_ID') return;

      if (window.hlcInitShowMore) { window.hlcInitShowMore(); }
    }
  );
});

These two events are the ones Toolset fires when the results have been replaced, and they’re intended for re-initializing third-party scripts.

Add the code in the View editor → Search & Pagination panel → JS editor (or a site JS file). Toolset’s “Adding custom JavaScript code to Views that use AJAX” guide shows the same pattern. For more information:

https://toolset.com/documentation/programmer-reference/adding-custom-javascript-code-to-views-that-use-ajax/

Please note: The request is considered a custom development, and the codes suggested are not tested. Those are ideas to help you find a solution. Providing a working solution is outside of our support scope.

Thanks.