• Resolved peacherd

    (@peacherd)


    Hello there,

    I’ve started out using your page fragment <!– mfunc with some success, thanks for a great feature !

    But am running into some issues when trying to echo with a $post->ID.

    The portion of the code I’m trying to fragment :

    <!-- mfunc code --> global $post; echo getHotThumb($post->ID, false, true); <!-- /mfunc code -->

    The first load of the cache page works perfectly, but on the next load, I get the following error from WordPress : Notice: Trying to get property ‘ID’ of non-object. Thus the thumb count shows 0.

    I’m a beginner in all this, so if I have it all wrong, your help would be appreciated ?? Thanks !

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

    (@vmarko)

    Hello @peacherd,
    I am sorry about the issue you are having with Page Fragment Cache but I am happy to assist you with this.
    Can you please check this article. Make sure to follow the instructions.
    I hope this helps

    Thread Starter peacherd

    (@peacherd)

    Thanks @vmarko, I had made all those specific changes but it must have been an error with the cache since 30 minutes after your message everything came back in to order with no errors.

    I do have another question. Is there a way of keeping $post->ID unchange while passing through the mfunc ? Since when dealing with an archive all the $post->ID reflect the id of the page they are contained in but not the id they originally come from. Do you have a solution for that?

    Thanks !

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @peacherd,

    I think there might be a while loop on an archive page. Within the loop, you have a mfunc
    but in the mfunc, the $post->ID is not correct.
    That’s because the mfunc doesn’t know the loop, only the page it’s loading.
    You could loop inside the mfunc, or you should use AJAX to update the page realtime.
    It is a pretty complex thing you are asking but I hope this helps!

    Thread Starter peacherd

    (@peacherd)

    Ok, thanks for your help @vmarko, I’ll see if I can figure it out!

    Regards,

    Thread Starter peacherd

    (@peacherd)

    Hello @vmarko,

    I’m sorry for coming back but the issue has risen again…

    I have followed all the instructions in the pdf you sent me.
    As I said, the portion of code I’m trying to fragment :
    <!-- mfunc code --> global $post; echo getHotThumb($post->ID, false, true); <!-- /mfunc code -->

    “The first load of the cache page works perfectly, but on the next load, I get the following error from WordPress : Notice: Trying to get property ‘ID’ of non-object. Thus the thumb count shows 0.”

    Any idea of what I’m doing wrong?

    Thanks

    Thread Starter peacherd

    (@peacherd)

    To add to this : the non-cached version for logged-in users works without a flaw. Only the cached page has the “Trying to get property ‘ID’ of non-object” error.

    Thanks

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @peacherd,

    Can you please confirm if the late initialization checkbox is checked? The reason you are getting the id of non-object error is because the global $post object is undefined when the page is cached. The reason non-cached works is because then the loops are run etc, which we skip with cache for a reason. Late initialization causes WordPress functions to be enabled and he should use get_the_ID() instead of global $post; and $post->ID.

    Thread Starter peacherd

    (@peacherd)

    Hi @vmarko,

    Yes, late initialization checkbox is checked as per image : screenshot

    I have tried get_the_ID(), but when I echo it, there is no ID shown on the cached paged (without cache it echoes the ID).

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Page fragement caching’ is closed to new replies.