Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #589105

    Page preview is not working when using the Avia framework, not even with the fix found here: https://kriesi.at/support/topic/no-preview-with-enfold-in-dev-website/

    I devised a better fix, see filter below (copy / paste it in your functions.php file)

    /*
    Fix an issue where previewing a page does not show modified changes when using the Avia framework
     */
    function avia_preview_fix($content)
    {
        if (is_preview())
        {
            /*
             The latest preview for this author is *probably* the one we want:
             - post_parent = 0 for all previews
             - post_type = revision for all previews
             - post_status = whatever the current status of the current post / page being previewed is
             - author = always the current logged in user
             - sort by descending date since the most recent one is the one we need
             - this way we need to only retrieve one post
             */
    
            $wpq = new WP_Query(array(
                'post_parent' => 0,
                'post_type' => 'revision',
                'post_status' => 'any', // change this maybe to the post status of the post being previewed?
                'author' => get_current_user_id(),
                'orderby' => 'date',
                'order' => 'DESC',
                'posts_per_page' => 1
            ));
    
            // double check if there are any posts
            if ($wpq->posts)
            {
                // overwrite content with the latest preview content
                $content = $wpq->posts[0]->post_content;
            }
        }
        return $content;
    }
    add_filter('avia_builder_precompile', 'avia_preview_fix', 99, 1 );

    Feel free to bestow us with a bit more free support in return ;-)

    • This topic was modified 8 years, 9 months ago by kracht12.
    #589121

    Hey kracht12!

    thanks a lot for sharing your solution with us.

    Cheers!
    Andy

    #589189

    He Andy,

    You’re welcome!

    My solution depends on the autosave feature that seems to be called each time you press the preview button. However it seems that sometimes saving the preview takes more time than loading the preview so you might end up with either an older preview or no preview (the current version). It usually does provide better results compared to using get_the_content() since that sometimes returns a preview made by another user that previously edited the page, or no preview at all (the current version again). Also, post_parent is better omitted, I saw instances (in the database) where post_parent was either 0 or the current post_ID so that is a bit buggy / random.

    I hope you find a use for this fix, however I haven’t seen anyone else having a problem with previews since the support topic from december 2013 so your solution seems to working fine for most users.

    #590941

    Hi!

    thanks for the additional info.

    Let us know in a new ticket if you have some more questions related to the theme. We are happy to assist you.

    Best regards,
    Andy

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.