List only posts from specific category on category page

You are complicating everything with a custom query. You should never ever replace the main query with a custom one on the home page or any type of archive page, this breaks page functionalities as you have seen. You should take your time and read this post I have done on this particular issue You … Read more

WP_Query Group by Author and Order each group DESC

EDIT 2 My idea in edit one did not work, so I scrapped it. This edit I have sorted the returned array using a foreach loop to sort the posts according to date under the specific author, and the author on top has the newest posts. The code below is tested and working, so you … Read more

Adding a parameter to the default query

I think the cleanest method here is just run a custom query, get the ID and then remove that post from the main query with post__not_in. You can additionally run a query inside a function and then call the function in your featured section and in pre_get_posts. There is another way, using a global to … Read more

Sort users by “birthday” using WP_User_Query

User Meta Query with RLIKE: If the birth date is stored like dd/mm/yyyy, in the user meta, then you could find all August birthday users with the following meta query: ‘meta_query’ => [ [ ‘key’ => ‘birthday’, ‘value’ => ‘/08/’, ‘compare’ => ‘RLIKE’ ], ] You could also consider storing the birthday month additionally in … Read more

How to use WP_Query to display many posts?

The p (post) paremeter for WP_Query accetps a single value only: $args = array( ‘p’ => 100 ); For multiple posts use post__in and pass an array of post ids: $args = array( ‘post__in’ => array(100, 102, 105) ); See Post & Page Paremters for further clarification.

How to pass many ids in post__in?

Don’t concatenate your id values into a comma separate string otherwise you will have to explode() by comma delimiter which is pointless, instead, if you are getting IDs from some other business logic as evidenced in your iteration over $rows, then build an array of IDs as per the following example: $ids = array(); foreach … Read more

Date and Category query with filter

I was going about this the wrong way around. I needed to allow the user to select the date first and then the category. I also needed to make the dropdown boxes auto select, so that the date search is performed first taking the user to the date archive and then the user can select … Read more

How to add post_distinct filter to WP_Comment_Query?

Okay, I understood by now, that get_comments() is only for … well comments. The following is not very elegant, but it does work at least. $i = 0; while (count($comments) < $number) { $comment = get_comments( apply_filters( ‘widget_comments_args’, array( ‘number’ => 1, ‘status’ => ‘approve’, ‘post_status’ => ‘publish’, ‘offset’ => $i ) ) ); if … Read more