WordPress query reverse order

Since you are using ‘post__in’ in the ‘orderby’ parameter, the ‘order’ parameter will have no effect, however, you can simply reverse the array you are passing to ‘post__in’: $args = array( ‘post_type’ => ‘etlap’, ‘posts_per_page’ => 5, ‘post__in’ => array_reverse($ids), ‘post_status’ => ‘any’, ‘orderby’ => ‘post__in’ );

How can I show only 5 posts from the relationship?

You could use the key from the foreach <?php $c_lists = get_field(‘c_lists’); if ($c_lists) : foreach ($c_lists as $key => $post_ids) : if ($key > 4) break; ?> <a href=”<?= get_permalink($post_ids); ?>”><?= get_the_title($post_ids); ?></a> <?php endforeach; endif; ?>

Does WordPress run a post query when a page is invoked?

Yes, it does. Pages are just a type of post. If you visit, say, https://test.test/sample-page/, then this happens: WordPress checks the URL against its stored rewrite rules. On a normal site, https://test.test/sample-page/ will match (.?.+?)(?:/([0-9]+))?/?$, which the rule maps to index.php?pagename=$matches[1]&page=$matches[2]. WordPress performs a query using WP_Query, with the pagename argument set to pagename. Our … Read more

INSERT in table row fatal error

This is more or less a programming question. $wpdb is not available everywhere. It’s a global variable. If you want to use it inside your own functions, just add global $wpdb; at the first line of the function. For general programming questions, this might be another discovery for you: stackoverflow.com,it is about programming in specific. … Read more

How to Show Comment Count on Related Posts?

get_comments_number works in the loop. You’re using it outside. So do something like this $category = get_the_category(); $category = $category[0]; $category = $category->cat_ID; $posts = get_posts(‘numberposts=5&offset=0&orderby=post_date&order=DESC&category=’.$category); foreach($posts as $post){ setup_postdata($post); $total = get_comments_number(); echo ‘here we create the HTML and content for the post’; } wp_reset_query();

show x number of posts from y category on homepage

That sounds outside the scope of what you’re going to get from query_posts. If you have a custom template for your home page and you want to sprinkle in advertisement posts I would change the query_posts() that excludes the advertisement category, do a separate get_posts() for 2 posts in the advertisement category, and then put … Read more