• Resolved rickfitz

    (@rickfitz)


    Hi – I’m getting problems using ‘show_excerpt’ on PHP7.2, when a post has no specific excerpt defined so has to extract it from post content. This looks like WP ticket #42814, relating to getting post content from outside the loop.

    I’m not sure where’s best to fix this! I’ll just revert to PHP7.1 until it’s resolved. The WP ticket has been open for ages – currently tagged for 4.9.9.

    I think there’s a feeling that get_the_content() and get_the_excerpt() are meant to be used inside the loop, and plug-ins are responsible for sorting out issues elsewhere!

    Cheers, Rick.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter rickfitz

    (@rickfitz)

    UPDATE:
    Reverting to older PHP removed the error message, but the excerpt still didn’t work when not specifically defined for post – i.e. failed to create excerpt from post content.

    FIX:
    Inserting ‘setup_postdata($post);’ just before the call to ‘get_the_excerpt($post);’ seems to fix the problem, with any PHP version. (This sets up the necessary data as if the call was from within the loop, and is recommended in the WP Codex.)

    Note: the excerpt problem didn’t always occur – seemed ok on a test site, but not the real one – presumably depends on the state of the global vars when the ticker is rendered.

    HTH, Rick.

    Plugin Author Paul Jura

    (@pauljura)

    Hi,

    I couldn’t reproduce the error but did some reading and took your advice to call setup_postdata. Please get latest version and check if this resolves your issue.

    Cheers,
    Paul

    Thread Starter rickfitz

    (@rickfitz)

    Thanks for the update, but it’s causing a new problem!
    You’ve declared $post global, so the ticker shows the data from the current page (which is what the global $post holds), and not the specified post!

    My version looks like this:

       if ($options['show_excerpt'] == 'true') {
          setup_postdata( $post );  // RCF added
          $content .= ' - '.get_the_excerpt($post);
       }

    Just the commented line added – nothing else.

    Cheers, Rick.

    • This reply was modified 7 years, 8 months ago by rickfitz.
    • This reply was modified 7 years, 8 months ago by rickfitz.
    Plugin Author Paul Jura

    (@pauljura)

    Hi,

    The global thing I copied from a post on the WordPress site. Anyway, made the change as you suggest. Check the latest version again, please.

    Cheers,
    Paul

    Thread Starter rickfitz

    (@rickfitz)

    Looks correct to me. Can’t test immediately as I have several other mods in the file and it’s on a live site!

    I’ll email separately to describe my changes and see if you’d like to merge into your plugin or whether my requirement is too different to make it worthwhile.

    Many thanks for the really useful plugin and lightning fast support!

    Rick.

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

The topic ‘PHP7.2 error with ‘show_excerpt’ option’ is closed to new replies.