• Hi all, I’m hoping someone has an answer to this

    I’m using W3TC for page caching and I’m filtering out a piece of my posts loop so that it does not get cached. For this example, it’s a custom meta field for the number of post views.

    The value is not getting cached, so mfunc is working… but the issue I’m having is, all posts following the first post queried in the loop will have the same number of views value that was queried from the first post

    Example:
    If the first post only has 1 view, the rest of the posts will show 1 view even if they have many views.
    Result from loop:
    Post 1 – views 1
    Post 2 – views 1
    Post 3 – views 1

    When it should really be:
    Post 1 – views 1
    Post 2 – views 30
    Post 3 – views 25

    For single post pages, the mfunc works correctly and shows the correct number of views for each post.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi dschiffner

    I have the same problem, did you ever get it solved?

    I think it’s to do with the global $post getting cached / not refreshed, with each loop.

    I found the solution. Only done some preliminary testing but seems to work.

    I had this code that would output prices.

    <!--mfunc <?php echo W3TC_DYNAMIC_SECURITY;?> -->
    get_price_fragment( get_the_ID() );
    <!--/mfunc <?php echo W3TC_DYNAMIC_SECURITY;?> -->

    get_the_ID() would stick as the first product in the loop.
    After much trial and error then a bit of luck I have found this to work.

    <!--mfunc <?php echo W3TC_DYNAMIC_SECURITY;?> -->
    get_price_fragment( <?php echo get_the_ID(); ?> );
    <!--/mfunc <?php echo W3TC_DYNAMIC_SECURITY;?> -->

    Basically echoing the get_the_ID() so it’s output by php not mfunc.

    Hope this helps!
    🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘W3TC – MFUNC in a loop’ is closed to new replies.