WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
[resolved] add_action (plugin) even with Cache ON (4 posts)

  1. Ricard Torres
    Member
    Posted 3 years ago #

    Hi Frederick,

    I was wondering if it is posible to use the add_action function even with caching the page.

    I have a Stats plugin wich calls:

    add_action('wp','es_pageviews');

    function es_pageviews(){
    	if(is_single() || is_page()){
    		global $post;
    		$pv = get_post_meta($post->ID, '_pageviews',true);
    		update_post_meta($post->ID, '_pageviews', $pv+1);
    	}
    }

    Very simple, as you can see.

    Using W3 Total Cache it gets cached, of course.

    Is there any chance I can force it to run the function? (even if the W3 Total Cache shows the static page as usual)

    I mean... update the post_meta "on background".

    Waiting for answer,

    Thanks.

  2. Ricard Torres
    Member
    Posted 3 years ago #

    I've tried:

    <!-- mfunc -->es_pageviews(); the_pageview();<!-- /mfunc -->

    1) I've added mfunc exception in the Minification settings.

    2) I've turned off the Database Settings.

    It works.

    I activated the Debug Mode for the Database but I don't see the page views query :(

    Is there any way I can turn ON the Database Caching but adding an exception?

    Thank you.

  3. Frederick Townes
    Member
    Plugin Author

    Posted 3 years ago #

    mfunc will not support any WordPress code because caching runs before WordPress can ever load.

  4. Ricard Torres
    Member
    Posted 3 years ago #

    Interesting.

    Like I said it works for now but with the dabase cache off :)

    As you can see here http://php.quicoto.com/how-to-get-the-visitor-ip/

    The page is cached but the pageview counter (under the title) keeps counting.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic