Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't my properly defined variable evaluate for length correctly (and subsequently work in the rest of my code)?
    text
    copied!<p>I employed the answer Marc B suggested and still got nothing in the variable when I echo'd it after the while loop, so I added a few checks to show status of things as they were processed through the code. When the if/else statement runs next, it shows the result that there is length to the variable. The next if/else statement branches to the else statement and then takes the else statement in the next if/else saying the xpath found nothing. So obviously when I go to use the variable $BEmp3s, it has nothing in it.</p> <p>This doesn't make much sense to me since in the beginning, the echo of $BEpost_content shows the proper content in its entirety but the evaluation on its length shows nothing/NULL? Please help!</p> <pre><code>&lt;?php // Start MP3 URL $doc = new DOMDocument(); $doc-&gt;strictErrorChecking = FALSE; $xpath = new DOMXpath($doc); // End MP3 URL $a = 1; if (have_posts()) : while ( have_posts() ) : the_post(); ?&gt; &lt;?php $BEpost_content = get_the_content(); if (strlen($BEpost_content) &gt; 0) { echo "&lt;div id='debug_content'&gt;get_the_content has something&lt;/div&gt;"; } else { echo "&lt;div id='debug_content'&gt;BEpost_content is empty&lt;/div&gt;" ; }; $success = $doc-&gt;loadHTML($BEpost_content); if ($success === FALSE) { echo "&lt;div id='debug_loadcontent'&gt;loadHTML failed to load post content&lt;/div&gt;"; } else { $hrefs = $xpath-&gt;query("//a[contains(@href,'mp3')]/@href"); if ($hrefs-&gt;length &gt; 0) { echo "&lt;div id='debug_xpath'&gt;xpath found something&lt;/div&gt;"; } else { echo "&lt;div id='debug_xpath'&gt;xpath found nothing&lt;/div&gt;"; }; $BEmp3s = $hrefs-&gt;item(0); }; ?&gt; </code></pre> <p>Here is the function get_the_content() which returns a string to my knowledge:</p> <pre><code>function get_the_content($more_link_text = null, $stripteaser = 0) { global $post, $more, $page, $pages, $multipage, $preview; if ( null === $more_link_text ) $more_link_text = __( '(more...)' ); $output = ''; $hasTeaser = false; // If post password required and it doesn't match the cookie. if ( post_password_required($post) ) { $output = get_the_password_form(); return $output; } if ( $page &gt; count($pages) ) // if the requested page doesn't exist $page = count($pages); // give them the highest numbered page that DOES exist $content = $pages[$page-1]; if ( preg_match('/&lt;!--more(.*?)?--&gt;/', $content, $matches) ) { $content = explode($matches[0], $content, 2); if ( !empty($matches[1]) &amp;&amp; !empty($more_link_text) ) $more_link_text = strip_tags(wp_kses_no_null(trim($matches[1]))); $hasTeaser = true; } else { $content = array($content); } if ( (false !== strpos($post-&gt;post_content, '&lt;!--noteaser--&gt;') &amp;&amp; ((!$multipage) || ($page==1))) ) $stripteaser = 1; $teaser = $content[0]; if ( ($more) &amp;&amp; ($stripteaser) &amp;&amp; ($hasTeaser) ) $teaser = ''; $output .= $teaser; if ( count($content) &gt; 1 ) { if ( $more ) { $output .= '&lt;span id="more-' . $post-&gt;ID . '"&gt;&lt;/span&gt;' . $content[1]; } else { if ( ! empty($more_link_text) ) $output .= apply_filters( 'the_content_more_link', ' &lt;a href="' . get_permalink() . "#more-{$post-&gt;ID}\" class=\"more-link\"&gt;$more_link_text&lt;/a&gt;", $more_link_text ); $output = force_balance_tags($output); } } if ( $preview ) // preview fix for javascript bug with foreign languages $output = preg_replace_callback('/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output); return $output; </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload