Wordpress: get_post_field() throws error like it's trying to redefine a function
<p>I have a function called <code>getNews()</code>.  </p>

<p>I call <code>getNews()</code> like this:</p>

<pre><code>&lt;div class="wrapper" id="blog"&gt;
    &lt;div class="blogPosts"&gt;
        &lt;?PHP getNews($postPerPage, 0, $theme_link, $pageNum); ?&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>The function works until it tries to get the article text from wordpress using <code>get_post_field()</code>.</p>

<pre><code>function getNews($numPosts, $offset, $theme_link, $pageNum) {
    $offset = $numPosts * $pageNum;
    $recent_args = array('numberposts' =&gt; $numPosts, 'offset' =&gt; $offset,);
    $articles = wp_get_recent_posts($recent_args);
    foreach($articles as $article){
        $article_id = $article['ID'];
        ...
        echo $article_text = get_post_field('post_content', $article_id);
        ...
    }
}
</code></pre>

<p>When I run this, I get the error saying <code>Fatal error: Cannot redeclare getNews() (previously declared in /homepages/30/d545089862/htdocs/VintageTroubleMusic/wp-content/plugins/enhanced-text-widget/enhanced-text-widget.php(57)</code></p>

<p>For some reason, it's running my loop twice.</p>

<p>Any advice?</p>

<p><strong>EDIT</strong></p>

<p>I'm including the full code here:  This is written inside of an "Enhanced Text widget" inside of a page.</p>

<pre><code>&lt;?PHP
    $theme_link = "/wp-content/themes/thestory-child/";
    $pageNum = $_GET['pa'];
    $postPerPage = 27;
    $qry_numPosts = mysql_query("SELECT * FROM Ykcfdlqhposts WHERE post_status = 'publish' AND post_type = 'post'") or die(mysql_error());
    $numPosts = mysql_num_rows($qry_numPosts);              
    $numPages = ceil($numPosts/$postPerPage) . " pages";
    if(!$pageNum){
        $pageNum = 0;   
    }
?&gt;
&lt;!-- START OF THE BODY HERE --&gt;
&lt;h3 class="widget-title" style="float:left;"&gt;Headlines&lt;/h3&gt;
&lt;div class="wrapper" id="paginate1"&gt;
    &lt;?PHP paginate($numPosts, $numPages); ?&gt;
&lt;/div&gt;
&lt;div class="wrapper" id="blog"&gt;
    &lt;div class="blogPosts"&gt;
        &lt;?PHP getNews($postPerPage, 0, $theme_link, $pageNum); ?&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;div class="wrapper" id="paginate2"&gt;
    &lt;?PHP paginate($numPosts, $numPages); ?&gt;
&lt;/div&gt;
</code></pre>

<p>And inside of the <code>functions.php</code> page</p>

<pre><code>function getNews($numPosts, $offset, $theme_link, $pageNum) {
$offset = $numPosts * $pageNum;
$recent_args = array('numberposts' =&gt; $numPosts, 'offset' =&gt; $offset,);
$articles = wp_get_recent_posts($recent_args);
foreach($articles as $article){
    $article_id = $article['ID'];
    $article_link = get_permalink($article_id);
    $article_length = 350;
    $article_background = get_the_post_thumbnail($article_id);
    $article_title = get_post_meta( $article_id, 'short_title', true );
    $article_text = "test";
    $article_text = get_post_field('post_content', $article_id);
    //$article_text = get_post_field('post_content', $article_id);
    //$article_text = strip_tags($article_text);
    //$article_text_length = strlen($article_text);
    /*
    if($article_text_length &gt;= $article_length) {
        $article_text_pos = strpos($article_text, " ", $article_length);
        $article_text = substr($article_text, 0, $article_text_pos)."... ";
    }
    */
    ?&gt;

    &lt;div class="article"&gt;
        &lt;?PHP //Get the article image
        if (!$article_background) {
            $rand = rand(1, 5);
            $img = $theme_link . "images/img" . $rand . ".jpg";
        } else {
            $img = explode('src="', $article_background);
            $img = explode(".jpg", $img[1]);
            $img = $img[0] . ".jpg";
        }?&gt;   
        &lt;a href="&lt;?= $article_link; ?&gt;"&gt;
            &lt;div class="article__image" style="background-image: url('&lt;?= $img; ?&gt;');"&gt;&lt;/div&gt;
            &lt;div class="article__title"&gt;&lt;?= $article_title; ?&gt;&lt;/div&gt;
        &lt;/a&gt;

        &lt;div class="article__details"&gt;
            &lt;div class="article-text"&gt;
                &lt;?= $article_text; ?&gt; 
            &lt;/div&gt;
            &lt;a href="&lt;?= $article_link; ?&gt;"&gt;READ MORE&lt;/a&gt;
        &lt;/div&gt;
    &lt;/div&gt;
 &lt;? }
}
function paginate($numPosts, $numPages) {
?&gt;
&lt;div class="page"&gt;
    &lt;span&gt;Page:&lt;/span&gt;&lt;?PHP
        $i = 0;
        while($i &lt; $numPages){
            $i++;
            if($i == $pageNum){
                echo '&lt;a href="?pa='.$i.'"&gt;&lt;span style="background-color:transparent; text-decoration:underline; color:white; cursor:default;"&gt;'.$i.'&lt;/span&gt;&lt;/a&gt;';
            } else {
                echo "&lt;a href='?pa=".$i."'&gt;&lt;span&gt;".$i."&lt;/span&gt;&lt;/a&gt;";    
            }
        }
    ?&gt;
&lt;/div&gt;
&lt;?
}
</code></pre>