Why not showing all post by default in my jquery filter

@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

Sort order in get_posts [closed]

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

get_post_fields as an excerpt

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

numberposts not responding to wp_reset_postdata()

@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.

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

Populate metabox dropdown with post title from another Custom Post Type (issues with wp_reset / global $post)

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