• Resolved speedysweedy

    (@speedysweedy)


    I hope I have the right forum to post this… Something has changed in WordPress that won’t allow some of my custom PHP code to work. My child theme stopped working correctly as of a couple months back. I’ve isolated the code within functions.php that is causing the issue but I need help understanding why it suddenly doesn’t work anymore. If I comment out the section of the code that says “$strOutput = $strOutput . ‘<div style=”margin-top:3px; margin-bottom:3px;width:50%;”>’ . do_shortcode(‘[audio src=”‘ . $audio_info[guid] . ‘”]’) . ‘</div>’;” the site displays correctly, when uncommented, the entire lower section of my <body> is missing.

    Here is the code.

    function shortcode_insert_sermons () {
        
        query_posts(array('post_type' => 'message','showposts' => 0, 'orderby' => 'post_date', 'order' => 'DESC')); 
        $strOutput = '';
        
        if (have_posts()) : 
    		while ( have_posts() ) : the_post();
    			$strOutput = '<article class="et_pb_post">';
    			$strOutput = $strOutput . "<h2 class='entry-title'><a href='" . get_permalink() . "'>" . get_the_title() . "</a></h2>";
                $strOutput = $strOutput . '<p>' . the_date('M j, Y','','',false) . '</p>';
                $audio_info = get_post_meta(get_the_ID(), 'message_audio', TRUE);
                if ($audio_info) {
    				$strOutput = $strOutput . '<div style="margin-top:3px; margin-bottom:3px;width:50%;">' . do_shortcode('[audio src="' . $audio_info[guid] . '"]') . '</div>';
    
                }
                $strOutput = $strOutput . '<p>' . get_the_excerpt() . '</p>';
                $strOutput = $strOutput . "<p><a href='" . get_permalink() . "'>view sermon</a></p>";
                $strOutput .= '</article>';
    		endwhile;
    	endif;
        
        wp_reset_query();
    	
    	return $strOutput;
    }
    add_shortcode('insert_sermons', 'shortcode_insert_sermons');
    

Viewing 3 replies - 1 through 3 (of 3 total)
  • Just a guess but the documentation says showposts was replaced by posts_per_page in release 2.1 that was 16 years ago

    I suggest trying replacing ‘showposts’ => 0 with ‘posts_per_page’ => -1

    Also I’d try quoting $audio_info[guid]

    i.e. $audio_info[‘guid’]

    In recent version of PHP the unquoted string will be treated as an undefined constant and in PHP 8 it will fatal so it wont be sending what you think to the audio shorcode

    Thread Starter speedysweedy

    (@speedysweedy)

    I think you nailed it with the quotes around guid. I changed the line to be esc_attr($audio_info[‘guid’] ) and now it works great. Thank you very much Alan, appreciated!

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

The topic ‘PHP code causing me grief’ is closed to new replies.