Why am I getting no results of a query placed after another query?
Why am I getting no results of a query placed after another query?
Why am I getting no results of a query placed after another query?
@HappyArif You just kept a line in your code that needs to be changed if there is a Category selected. $args = array( ‘orderby’ => ‘date’, ‘post_type’ => ‘course’, ‘posts_per_page’ => -1, ‘tax_query’ => $tax_query, ); This have ‘posts_per_page’ => -1 which needs to be changed to ‘posts_per_page’ => 9, ‘paged’ => $paged to make … Read more
I removed the following line and fixed. <span><?php the_field(‘repeater_related_items’); ?></span>
Your description of the problem is not very clear, and your inconsistent code formatting makes that hard to read (plus I am pretty sure some code is missing), but if the problem is running the query multiple times you can solve that with a static variable. function get_gametitle_info() { static $game_info_query = false; if (false … Read more
The problem here is not that the posts that are being wrongly displayed are displayed under the wrong category, it’s that they’re not actually in the right category. For example, the post “Supporting healthy eating choices” is displayed under “O” as it has the category “O”. Going to your backend and assigning the proper category … Read more
Give this a try. Basically, your get_posts looks OK, but you need to setup the post information. This leats you use the normal functions the_something and get_something without having to pass in a post object / ID each time. Just remember to call wp_reset_postdata(); anytime you use setup_postdata(). <?php $random_post = get_posts(array( ‘category’ => ‘objects’, … Read more
Correct Way To Run Multiple Queries Sharing Some Base Data
@Milo’s answer worked perfectly (see comment above). if (in_array($post->ID, $do_not_duplicate)) continue; meant that duplicate posts were still being counted in the loop, though not being displayed. To fix, remove this line, and exclude duplicate posts from the query with this argument: ‘post__not_in’ => $do_not_duplicate. Thank you @Milo for your swift and succinct response.
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
Okay, I’ve got it sorted. I found a post on here with something similar; WordPress wasn’t resetting back into the main loop. So my code is now: /* Show roles metabox */ function show_roles_metabox() { global $post; $tempPost = $post; wp_nonce_field(basename(__FILE__), ‘role_nonce’); $pro_areas = array( ‘One’, ‘Two’, ‘Three’ ); $args = array( ‘post_type’ => ‘proarea’, … Read more