If you switch to get_posts
you don’t have to worry about resetting the loop.
function SliderBuilder( $categoryID ) {
$args = array (
'cat' => $categoryID,
'posts_per_page' => 3,
);
$posts = get_posts( $args );
echo $categoryID;
?>
<ul class="blog-slider" id="blog-slider">
<?php
foreach ( $posts as $post ) { ?>
<li class="blog-slide" onclick="location.href="https://wordpress.stackexchange.com/questions/243846/<?php echo get_the_permalink( $post->ID ); ?>";">
<div class="blog-thumb">
<?php echo get_the_post_thumbnail( $post->ID, 'small-thumbnail' ); ?>
</div>
</li>
<?php
}
?>
</ul>
<?php
}
SliderBuilder( 2 );
SliderBuilder( 3 );
Related Posts:
- Multiple Loops Inside a Function
- Reset postdata to custom query in nested queries
- reset to main loop doesnt work
- how to use pre_gets_posts to exclude one queried ID from homepage loop
- relation OR instead of AND – Filtered term ID’s in loop
- Custom query for custom post type not getting correct post ID
- What’s causing an infinite loop?
- Get post Number with local loop and template
- Problem with custom WP_Query and underlying pagination/posts_per_page
- How to write a query-function as a query-shortcode?
- Some doubts about how the main query and the custom query works in this custom theme?
- Using a custom WP_Query with get_template_part loop
- Loop within a loop?
- Use WP_Query with have_posts()?
- Where should you reset postdata?
- Why should i use wp_reset_postdata()?
- ajax category filter
- Display posts the match taxonomy term linked from wp_list_categoies?
- WordPress 4.9.5 PHP intermittent warning trim() expects parameter 1 to be string, array given
- Loop through all tags & output posts in alphabetical list
- Merging a complex query with post_rewind and splitting posts into two columns
- Pagination Not working on Home Page with 2 Query
- meta_query not working properly
- How to get any tag ID
- Exclude post on loop by multiple meta key value
- Sort by meta key on archive page
- Query sticky posts with thumbnails
- Show all parents and children in custom post type in right order
- Why is this coming back as null? Thats wrong. There is one post
- Ignore post by meta value in the main query
- WP_Query to get posts in a specific category and post format
- Can’t get drafts with WP_Query using post_status parameter
- How to retrieve current page WP_Query arguments?
- How to limit WP_Query to one result on the loop?
- Exclude admin from WP_Query Contributors
- Random loop with code to prevent duplicate output returns no output at all from time to time
- How to use offset in WP_Query
- Multiple loops without repeating content
- Change query based on post type while staying in loop
- Filtering posts from different categories into different section by doing WP_Query only once
- wordpress search word, “hello world” ===> ‘hello+world’ ===> ‘hello’, ‘world’
- $WP_Query: How to display excerpt on first post only
- How to make search for posts using get method?
- Custom taxonomy.php not working
- different for loop if screen resolution < 1000px
- Transient api Caches confused
- Admin Page Post Id wp_reset_postdata not working
- sort and display posts by custom field (wp-query and the loop))
- WP_Query – Adding “offset” posts to the end of the loop
- Conditional operator OR not working with custom fields
- wp_query is showing posts from other categories
- Should I reset $wp_query?
- How to load a script code only in posts?
- inserting content of 1 Post to in another with a template hierarchy
- Pagination for custom loop on custom page template is not displaying anything
- Filtering by multiple conditions in the loop
- How to access $wp_query object from array of posts given by get_posts?
- Display all attached image of every post of custom post type and link to original post
- Writing less unnecessary code with WordPress
- How do I get the content of a custom instance of WP_Query?
- WordPress Queries Not Working?
- Filter subpages in while loop from WP Query object
- Use have_posts() with array of post results retrieved by $wpdb->get_results
- Custom query does not find pages
- How to sort by most watched in X days/months
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- How can I use arrays and a foreach to generate many lists with WP_Query?
- How to use custom page for all posts with custom url, call another directory?
- display ACF repater field in archive page
- Pagination repeating posts on search results
- WP_Query breaking the loop in a nested loop
- ACF: How can I publish values of ACF fields in a loop while using wp_query?
- Show a message if there are no active posts in category
- Related posts queries
- Problem with my loops
- update_post_meta() not updating
- Paging works correctly on local version, but not live?
- why default wordpress loop not working outside index.php
- how to show more than 1 post into three columns query
- My query keeps looping infinitely ! how to stop it?
- How to make a wordpress loop file that displays posts based on certain conditions
- WP_Query secondary query failing
- Custom loop – Isolating post meta output depending on current query taxonomy terms
- Issue in If else condition [closed]
- Pagination not working with WP_QUERY
- Hiding all posts/products/pages from a site based on a custom taxonomy/domain name
- Custom search (wp query by custom fields)
- Sorting is not working in WordPress WP_Query
- Add custom WP_Query after the first 3 posts
- How do I display posts with specific value in a custom field into my loop?
- Limit the number of posts from a specific category on index.php
- Order by multiple meta keys on wordpress
- wp_query pagination links producing 404
- Display First posts without the default featured image
- Pagination problem with multiple loops on the same page
- Query for page content, and query for posts on the same page?
- Can’t seem to get an else statement correct? [closed]
- Output ACF field dynamicaly within a taxonomy loop [closed]
- How do I split a large query with a semi-expensive function included into multiple smaller queries
- Show number of posts AND number on current page (cannot make it work)