Calling a function with WP_Query only ever brings the first result

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( … Read more

Querying posts from two different categories while looping inside another loop

You should not be using query_posts() for this or anything else. For secondary loops you should be making new WP_Query instances. Since you can (and should) assign instances to different variables they won’t interfere with each other. So your structure would be roughly like this: $outer_query = new WP_Query(); while( $outer_query->have_posts() ) : the_post; $inner_query … Read more

WordPress infinite post cycle problem

If I understood you right you want to list all of your posts on one page. To do so, try something like this: <?php if ( have_posts() ) { while ( have_posts() ) { the_post(); ?> <a href=”https://wordpress.stackexchange.com/questions/244113/<?php next_post_link(); ?>”> <div class=”featured-image”><?php the_post_thumbnail(); ?></div> <div class=”content”><?php the_content(); ?></div> <?php } // end while } // … Read more

WordPress infinite post cycle

It should be more simple. Like this: <?php $next_post = get_previous_post(); if( empty( $next_post ) ) { $posts = get_posts( array( ‘posts_per_page’ => 1 ) ); $next_post = $posts[0]; } ?> <a href=”https://wordpress.stackexchange.com/questions/244656/<?php echo get_permalink( $next_post->ID ); ?>”> <span class=”next”></span> <div class=”featured-image” style=”background-image: url(‘<?php echo wp_get_attachment_url( get_post_thumbnail_id( $next_post->ID ) ); ?>’)”></div> </a> <div class=”content”> <?php … Read more

Only show current category post

Use the function get_the_category(); inside the WordPress loop and pass the get_the_ID() function which will get the current post ID in the loop. get_the_ID() will return the post id and whereas the the_id(); will just display. if( $the_query->have_posts() ) : while( $the_query->have_posts() ) : $the_query->the_post(); $category_array = get_the_category( get_the_ID() ); print_r( $category_array ); endwhile; endif; … Read more

Problem with custom WP_Query and underlying pagination/posts_per_page

Stop overriding the default loop and use pre_get_posts instead. Like this: function wpse_247208_custom_category_query( $query ) { // Return early for any situation you aren’t interested in. if ( is_admin() || ! $query->is_main_query() || !is_category() ) { return; } $query->set( ‘posts_per_page’, 6 ); // Don’t use a global; create a function to populate this value // … Read more