• Resolved kechuvitalione

    (@kechuvitalione)


    Hello, how are you all? I need to know if there is a possibility that with a code when pressing a button and confirming an operation the cache of a specific url can be purged, this is what I have but it doesn’t work. I was able to make it do the general purge but not the purge of a specific page:

    // Después de confirmar la venta con éxito
    add_action(‘wp_ajax_agregar_venta’, ‘agregar_venta’);
    add_action(‘wp_ajax_nopriv_agregar_venta’, ‘agregar_venta’);
    function agregar_venta() {
    // Tu código para agregar la venta…

    // Purgar la caché solo para la URL específica
    purgar_cache_para_url('https:ejemplo');
    
    wp_die(); // Detiene la ejecución del script

    }

    function purgar_cache_para_url($url) {
    // Comprueba si el plugin de caché está activo
    if (function_exists(‘lscache’)) {
    // Purga la caché solo para la URL específica
    lscache()->purgeUrl($url);
    }
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • mukoka

    (@mukoka)

    Unfortunately, the cache plugin does not have the desired function, although LScache supports purge cache by URL. That’s why you have to create a custom solution that is independent of WordPress and the cache plugin.

    <?php
    header(x-litespeed-purge: /cache_url_by_url);

    This does the trick.

    • This reply was modified 12 months ago by mukoka.
    Thread Starter kechuvitalione

    (@kechuvitalione)

    Thank you very much, the last question: how can I add this to a code to use it with a shortcode?

    Plugin Support qtwrk

    (@qtwrk)

    if (defined('LSCWP_V')){
    do_action( 'litespeed_purge_url', '/something/somepage/' );
    }

    please try this

    what do you mean with a shortcode ? like purge cache by shortcode ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Purge cache for url’ is closed to new replies.