Title: PHP code causing me grief
Last modified: September 11, 2023

---

# PHP code causing me grief

 *  Resolved [speedysweedy](https://wordpress.org/support/users/speedysweedy/)
 * (@speedysweedy)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/php-code-causing-me-grief/)
 * 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.
 *     ```wp-block-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)

 *  [Alan Fuller](https://wordpress.org/support/users/alanfuller/)
 * (@alanfuller)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/php-code-causing-me-grief/#post-17042764)
 * 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
 *  [Alan Fuller](https://wordpress.org/support/users/alanfuller/)
 * (@alanfuller)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/php-code-causing-me-grief/#post-17042779)
 * 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](https://wordpress.org/support/users/speedysweedy/)
 * (@speedysweedy)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/php-code-causing-me-grief/#post-17043003)
 * 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.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Everything else WordPress](https://wordpress.org/support/forum/miscellaneous/)
 * 3 replies
 * 2 participants
 * Last reply from: [speedysweedy](https://wordpress.org/support/users/speedysweedy/)
 * Last activity: [2 years, 8 months ago](https://wordpress.org/support/topic/php-code-causing-me-grief/#post-17043003)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
