0
<?php 
    function getPosts($showposts,$tags, $thumb_key="thumb_300x166", $thumb_class, $thumb_width="300", $thumb_height="166") {

        $temp = $wp_query;
        $wp_query= null;
        $wp_query = new WP_Query();
        $wp_query->query('tag=$tags&showposts=$showposts');

        while ($wp_query->have_posts()) { 

            $wp_query->the_post();

            echo '<div class="entry"><div class="left">';

                if ( function_exists( 'get_the_image' ) ) {
                    $defaults = array(
                        'custom_key' => array( '$thumb_key' ),
                        'image_class' => '$thumb_class',
                        'image_scan' => true,
                        'width' => '$thumb_width',
                        'height' => '$thumb_height' 
                        );
                    get_the_image($defaults); // thumbnail
                } // end if

            echo '</div>
                  <div class="right">
                  <h3><a href="'.the_permalink().'">'.the_title().'</a></h3>'
                  .the_excerpt().'</div></div>';

        } // end while
    }
    getPosts($showposts=5,$tags="news",$thumb_class="review-thumb");
?>

I don't understand why this wordpress query function isn't working. I doesn't return/print anything at all.

2
  • Why don't we ever get questions where the function is working as expected.... Commented Feb 7, 2010 at 15:31
  • .. because no one wants to seek help when the function is working. Commented Feb 7, 2010 at 16:47

1 Answer 1

4

I have never used Wordpress, but I see one problem that might be the cause of this.

Which is that if you use single quotes, such as on the following line:

$wp_query->query('tag=$tags&showposts=$showposts');

$tags and $showposts are not processed and are inserted into the string literally. If you want your string to contain the values of $tags and $showposts, use double quotes, like this:

$wp_query->query("tag=$tags&showposts=$showposts");

The same goes for the array passed to get_the_image.

edit: Additionaly, your function call looks weird. You're using syntax similar to when you're providing default values for arguments, but a regular function call will look something like this:

getPosts(5, "news", "review-thumb");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.