• Hi Folks
    I have recently just updated a wordpress site for my son which used a very old and hacked theme to post video reviews. I finally was able to work out how to get the new theme to work and to get the old embedded videos to show on each post by adding this line of code:

    <?php $values = get\_post\_custom\_values(“video”); echo $values\[0\]; ?>

    This works great however each new post he does with the new theme doesnt require this code and because the video embed is missing from the new posts it throws up an error message but only on PHP 8, not any older php versions. Here is the message:
    Warning: Trying to access array offset on value of type null in /home/customer/www/movietube.com.au/public_html/wp-content/themes/justvideo/single.php on line 18
    Does anyone have a solution please? Thank you

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • The code is syntactically incorrect, as it would have been with earlier PHP versions. Syntactically correct would be:

    
    <?php $values = get_post_custom_values("video"); echo $values[0]; ?>

    I cannot judge whether this solves the problem as I do not know whether the line is in the position mentioned in the error message.

    Thread Starter Ink Hub

    (@jaydean7)

    Hi Threadi

    Thank you for your help but the line you posted is the same, nothings changed.

    Kind regards Dean

    Thread Starter Ink Hub

    (@jaydean7)

    Hi Threadi

    Sorry for some reason when I posted it the // were added to the code. The actual code was as you said in your post.

    Thread Starter Ink Hub

    (@jaydean7)

    Hi Folks
    I have recently just updated a wordpress site for my son which used a very old and hacked theme to post video reviews. I finally was able to work out how to get the new theme to work and to get the old embedded videos to show on each post by adding this line of code:

    <?php $values = get_post_custom_values("video"); echo $values[0]; ?>

    This works great however each new post he does with the new theme doesnt require this code and because the video embed is missing from the new posts it throws up an error message but only on PHP 8, not any older php versions. Here is the message:
    Warning: Trying to access array offset on value of type null in /home/customer/www/movietube.com.au/public_html/wp-content/themes/justvideo/single.php on line 18
    Does anyone have a solution please? Thank you

    The page I need help with: https://movietube.com.au/

    Thread Starter Ink Hub

    (@jaydean7)

    I assume that it needs some kind of “if” or “else” code added so if the video is not there it doesn’t throw up the error message.

    Thread Starter Ink Hub

    (@jaydean7)

    This is the full code for single.php

    <?php
    /**
     * The template for displaying all single posts.
     *
     * @link https://developer.www.ads-software.com/themes/basics/template-hierarchy/#single-post
     *
     * @package justvideo
     */
    
    get_header(); 
    ?>
    
    	<div class="single-wrap clear">
    
    	<div id="primary" class="content-area">
    
    		<main id="main" class="site-main">
    <?php $values = get_post_custom_values("video"); echo $values[0]; ?>	
    		<?php
    		while ( have_posts() ) : the_post();
    
    			get_template_part( 'template-parts/content', 'single' );
    
    			// If comments are open or we have at least one comment, load up the comment template.
    			if ( ( comments_open() || get_comments_number() ) && is_singular('post') ) :
    				comments_template();
    			endif;
    
    		endwhile; // End of the loop.
    		?>
    		</main><!-- #main -->
    	</div><!-- #primary -->
    
    	<?php get_sidebar(); ?>
    
    	</div><!-- .single-wrap -->
    
    <?php get_footer(); ?>
    
    
    
    • This reply was modified 11 months, 1 week ago by Ink Hub.

    Assuming that the $values variable will be always empty for the newer posts, and may have a value for older ones, you just need to echo the value:

    <?php
    $values = get_post_custom_values('video');
    if (isset($values[0])) {
    	echo $values[0];
    } ?>

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Issue with PHP8’ is closed to new replies.