The loop within functions.php

I’m using the loop within functions.php, and I know the loop isn’t working. Do I have to globalize anything? I’ve looked around, and I’m unsure. This is my function:

function loadDiffSection($name)
{
    $term = get_term_by('name', $name, 'category');
    $termIdFeat = $term->term_id;

    $everything = "";

    if(have_posts() ):
        query_posts("cat=".$termIdFeat."&posts_per_page=5");
        $count = 1;

        while(have_posts() ) : the_post();
            set_post_thumbnail_size(520 , 0, true);
            $everything .="<a href='?p=".the_ID()."'>";
                $everything .="<div class='pushLeft grid thisPost pos_".$count."'>";
                    $everything .="<div class='capMedia hide'>";
                            $everything .="<font size='3'>".get_the_title()."</font><br /><br />";
                            $actualLen = strlen(strip_tags(removeImagefromContent()));
                            $limit = 200;

                            if($actualLen > $limit)
                            {
                                $everything .= substr(strip_tags(removeImagefromContent()), 0, $limit)."...";
                            }
                            else
                            {
                                $everything .= strip_tags(removeImagefromContent());
                            }
                    $everything .= "</div>";
                    $everything .= get_the_post_thumbnail();
                $everything .= "</div></a>";
            $count++;
        endwhile;
    endif;
    header( 'Content-Type: application/json; charset=UTF-8' );
    echo json_encode(array("returned" => $everything));
    exit;
}

I’m using this code to call an AJAX request, so it’s returning a NULL response. This leads me to believe the loop isn’t working within the function.

Related posts

Leave a Reply

1 comment

  1. Looks to me like you need to enclose your while statement in the correct enclosure so to speak,

    while(have_posts() ) : the_post(); ought to be while((have_posts() ) : the_post());

    and then that ; on the end kills the while right there it out to look like this while((have_posts() ) : the_post()):

    It is a colon not a semi-colon needed. Try that.