• Resolved leem321

    (@leem321)


    Hi, I’ve managed to get the Page Fragment Cache block running okay, but noticed that I can’t seem to run any if/else logic against a php, or acf, field variable and I was wondering if this is perhaps just because of the life-cycle of how the page fragment caching works?

    For example I currently have this on my page:-

    <!– mfunc mysecuritystring –>

    if( get_field( ‘my_acf_field’ ) ){
    echo ‘hello world’;
    }

    <!– mfunc mysecuritystring –>

    But the get_field always return null…and the echo is never printed to the screen…

    However if I just var_dump the get_field value in normal php tags it will return true

    Many thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @leem321

    Thank you for your question and I am happy to help!
    “Page Fragment Cache” dynamically loads the content (in real-time) on your cached pages by parsing them for specific tags you manually embed. There is no reason the if/else logic would not work as you can see in the example in our FAQ.
    Make sure everything is correctly set up.
    Thanks!

    Thread Starter leem321

    (@leem321)

    Hi Marko, thanks for you response. Yes it seems I did have everything setup correctly from the back-end/plugin settings (Page Cache / Disk: Basic,
    Late initialization)

    I solved my particular problem by attempting to determine the current post id using the url_to_postid function inside the non-cache block e.g.

    <!– mfunc mysecuritystring –>

    $tmpW3TCURL = $_SERVER[‘REQUEST_URI’];
    $setPagePostID = url_to_postid( $tmpW3TCURL );

    if( get_field( ‘my_acf_field’, $setPagePostID ){
    }

    <!– /mfunc mysecuritystring –>

    Not sure how robust this is, but it seems to do the job from my initial testing…thanks again for the response.

    Regards

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

The topic ‘W3 Total Cache – ACF /PHP Variables’ is closed to new replies.