• Resolved hereismine

    (@hereismine)


    Hello!

    Can you help me? I got these error:

    Warning: Undefined array key “content” in /var/www/html/wp-content/plugins/code-snippets/php/front-end/class-frontend.php(210) : eval()’d code on line 7

    Warning: Undefined array key “author” in /var/www/html/wp-content/plugins/code-snippets/php/front-end/class-frontend.php(210) : eval()’d code on line 9

    and here is the code:

    <?php
    
    $data = wpgetapi_endpoint( 'quotable', 'random', array('debug' => false) );
    
    echo $data['content'];
    echo '<br>';
    echo $data['author'];
    
    ?>

    Thank you in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hi @hereismine,

    You’re attempting to access array keys in the snippet which don’t exist. This can be fixed by providing a fallback value with the ?? operator:

    <?php
    
    $data = wpgetapi_endpoint( 'quotable', 'random', array( 'debug' => false ) );
    
    echo $data['content'] ?? '';
    echo '<br>';
    echo $data['author'] ?? '';
    
    Thread Starter hereismine

    (@hereismine)

    I have tried your code and the warning is gone but why no data appears?

    Plugin Author Shea Bunge

    (@bungeshea)

    That’s just down to what the wpgetapi_endpoint is returning. The array you’re receiving doesn’t contain any items called content or author, which is why the error messages were being displayed.

    I’m not very familiar with where the wpgetapi_endpoint function comes from, so I’d recommend asking them how the function is supposed to work.

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

The topic ‘Undefined array key… eval()’d code on line…’ is closed to new replies.