Support » Fixing WordPress » Problem after changing PHP versio 5.6 to 7.4

  • Resolved zecke

    (@zecke)


    Hi i got this code:

    <?
    
    // set arguments for get_posts()
     $args = array[
     'numberposts' => '1',
     'orderby' => 'rand',
      'category' => '139',
      'exclude' => '5336,5334,5331,5329,5327,5325,5323,5321,5317,5313,5310,5272'	
     ];
    // get a random post from the database
     $my_random_post = get_posts ( $args );
    // process the database request through a foreach loop
     foreach ( $my_random_post as $post ) {
     // redirect the user to the random post
     wp_redirect ( get_permalink ( $post->ID ), 307 );
     exit;
     }
     
     ?>
    

    Its working fine on php ver.5.6 but when I change php to 7.4 it`s not working anymore… All i get is error like this:

    '1', 'orderby' => 'rand', 'category' => '139', 'exclude' => '5336,5334,5331,5329,5327,5325,5323,5321,5317,5313,5310,5272' ]; // get a random post from the database $my_random_post = get_posts ( $args ); // process the database request through a foreach loop foreach ( $my_random_post as $post ) { // redirect the user to the random post wp_redirect ( get_permalink ( $post->ID ), 307 ); exit; } ?>

    What to change in this code to make it run on php 7.4 ? Im sorry but Im not a programmer. Thanks for any help

    • This topic was modified 2 years, 1 month ago by zecke.
    • This topic was modified 2 years, 1 month ago by zecke.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator James Huff

    (@macmanx)

    Volunteer Moderator

    Try manually resetting your plugins (no Dashboard access required). If that resolves the issue, reactivate each one individually until you find the cause.

    If that does not resolve the issue, access your server via SFTP or FTP, or a file manager in your hosting account’s control panel (consult your hosting provider’s documentation for specifics on these), navigate to /wp-content/themes/ and rename the directory of your currently active theme. This will force the default theme to activate and hopefully rule-out a theme-specific issue (theme functions can interfere like plugins).

    Please change the opening PHP tag to ‘<?php’

    Also, a better way to write the $args array:

    $args = array(
               'numberposts' => 1,
               'orderby' => 'rand',
               'category' => 139,
               'exclude' => 
                array(5336,5334,5331,5329,5327,5325,5323,5321,5317,5313,5310,5272)	
             );

    I hope this will fix your issue.

    Kind regards

    Thread Starter zecke

    (@zecke)

    Thanks guys. Parshant Singh i change it and it works. Thanks again

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem after changing PHP versio 5.6 to 7.4’ is closed to new replies.