So I made a simple php script to display the top 3 posts in a category as a list. Pretty simple. Thing is I'm going to be using it quite a bit so I thought I'd be cleaver and write it out as a function where I could just pass the category ID number and it would generate the list. I'm new to php but I've done this often enough in JavaScript.
Problem is it only seems to want to display the first category i passed to it. I've done some reading but neither wp_reset_postdata(); wp_reset_query() OR rewind_posts() seem to work.
This seems like something which should be fairly simple but I really don't know how to proceed. Any help is hugely appreciated.
Here is my code with all the extra bits cut out:
<!--PHP Slider Unordered List Generator-->
<?php
function SliderBuilder($catagoryID) {
//Set up variables to convert catagoryID into useable string
$preped_catagoryID = "'cat=".$catagoryID."&posts_per_page=3'";
echo $preped_catagoryID;
?>
<ul class="blog-slider" id="blog-slider">
<?php
$catquery = new WP_Query( $preped_catagoryID );
while($catquery->have_posts()) : $catquery->the_post();
?>
<li class="blog-slide" onclick="location.href='<?php the_permalink();?>';">
<div class="blog-thumb">
<?php the_post_thumbnail('small-thumbnail'); ?>
</div>
</li>
<?php
echo $preped_catagoryID;
endwhile;
wp_reset_postdata();
?>
</ul>
<?php
}
SliderBuilder("2");
SliderBuilder("3");
?>