Posts loop with pagination on a single post page
The simple answer is, get_posts does not work with pagination. In stead you should use wp_query, like this: $args = array (‘posts_per_page’ => 5); $posts = new WP_Query ($args);
The simple answer is, get_posts does not work with pagination. In stead you should use wp_query, like this: $args = array (‘posts_per_page’ => 5); $posts = new WP_Query ($args);
How to show min 1 post from specific categories/tax WP_Query?
The method given in the WPSE answer you linked would exclude posts from the categories listed by ID in the array when the current query is the home blog page (not an archive page, or a category page, etc.). It is also not intended to affect secondary queries on the page. Placed in the functions.php … Read more
Multiple meta queries but arrange by specific meta value order
As other answers mentioned, you aren’t in The Loop so get_the_*() functions aren’t going to work properly. Since you’re looping over $query->get_posts() you can just use the WP_Post object. Something like this will work. foreach($query->get_posts() as $testimonial): $meta = get_post_meta($testimonial->ID); foreach($meta as &$m){ if(is_array($m)){ $m = $m[0]; } } <div class=”content”><?= do_shortcode($testimonial->post_content); ?></div> <div class=”author”>- … Read more
You can also add the following code before running new WP_Query: remove_all_filters(‘posts_orderby’); I believe this is self-explanatory.
WP_Query with tax_query, order by most ‘matches’
Personally I would do this after fetching the user id: echo ‘<pre>’; var_dump($user_id); echo ‘</pre>’; To check it is getting the $user_id as expected. (int) This should be a comment, but I am lacking reputation.
WooCommerce has a built in function that will do this for you called wc_get_related_products(). That will return an array of product IDs which you can then use in a proper custom loop. I recommend you avoid using WP_Query() and get_posts(). See here for an article I wrote on the right way to create a custom … Read more
Adding multiple post queries with parent and children to page – Best Way