• Resolved dallass

    (@dallass)


    Hello,

    First of all congratulation of the great plugin.
    I am using for years now and everything works great.

    Recently, I have developed a Q&A part of my site where users can mark the best answer.
    The marking of the best answer it is done by clicking on a button which adds a label “Best Answer” on the specific answer.

    When the cache it is on, that label does not appear until the cache is cleared.

    Is there a way to make this work ?

    P.S. Sorry, if I can’t give more technical details. I am not the programmer. But, if need, I can ask specific questions.

    • This topic was modified 5 years ago by dallass.
Viewing 15 replies - 1 through 15 (of 20 total)
  • Plugin Support qtwrk

    (@qtwrk)

    Hi,

    The best way to do this is to use our purge API

    LiteSpeed_Cache_API::purge_post($id)

    you need to integrate this onto function of the “Best answer” button.

    Best regards,

    Thread Starter dallass

    (@dallass)

    Can you please give me an example of how this can be done, please ?

    stanley@litespeed

    (@stanleylitespeed)

    Hi @dallass, do you know the page ID when you clicking the “Best Answer” button? Also, could you share the PHP code sample which triggers by the button click?

    Thread Starter dallass

    (@dallass)

    Hi,

    Yes, the page ID it is known.

    I put here https://pastebin.com/QXzw3jZu the content of the file.
    I think you have to check from line 1601 to 1654.

    stanley@litespeed

    (@stanleylitespeed)

    Thanks for the update. According to the JS code, if you click the button, it will make a post request to WordPress.

    Firstly you need to find out the action value on post request data: { action : 'wpqa_'+type... }, then add these rows to your theme’s functions.php:

    if ( $_POST[ 'action' ] === 'THE_ACTION_VALUE' ) {
    	LiteSpeed_Cache_API::purge_post( 'THE_POST/PAGE_ID' ) ;
    }

    (replace THE_ACTION_VALUE to the request action value, THE_POST/PAGE_ID to the page/post you’d like to purge)

    Thread Starter dallass

    (@dallass)

    Thank you for looking into this.

    The programmer that I am working with it is a bit stubborn.
    He said he made what you recommended, but it is still not working.

    I have added this function https://pastebin.com/VCvyf4t3 in a php file (admin_ajax.php) in the theme folder.
    And I have added this into functions.php

    add_action("wpqa_after_remove_best_answer","discy_child_after_best_answer");
    add_action("wpqa_after_choose_best_answer","discy_child_after_best_answer");
    function discy_child_after_best_answer($post_id) {
    LiteSpeed_Cache_API::purge_post($post_id);
    }

    I would appreciate if you could find the time to have another look.

    stanley@litespeed

    (@stanleylitespeed)

    If you have a hook on remove and choose the best answer this should able to work, what is the problem you facing now?

    Thread Starter dallass

    (@dallass)

    The cache it is not cleared for that post.

    So:
    – without cache, you see the best answer.
    – with cache, you do not see it (as the page was cached before the best answer was choosed)

    stanley@litespeed

    (@stanleylitespeed)

    Can you confirm the $post_id parameter from discy_child_after_best_answer() is the post you want to purge?

    Thread Starter dallass

    (@dallass)

    Yes, this is corect.

    stanley@litespeed

    (@stanleylitespeed)

    May I know does these two actions wpqa_after_choose_best_answer, wpqa_after_remove_best_answer on a POST request?

    Thread Starter dallass

    (@dallass)

    Sorry, but I did not understood your question.

    Thread Starter dallass

    (@dallass)

    Is it possible to have a solution ?

    Could you error_log($_SERVER['REQUEST_METHOD']) on discy_child_after_best_answer() to see when it has been triggered, is it a POST or GET reqeust?

    Thread Starter dallass

    (@dallass)

    It is a post.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Q&A sites’ is closed to new replies.