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

Query posts by specific word on title

The answer to this question is here. The full credit of the answer to my question goes for the author of the answer birgire. All I had to do was slightly change is plugin “Support for post name like in WP_Query” turning it into a function like this: add_filter( ‘posts_where’, ‘title_like_posts_where’, 10, 2 ); function … Read more

Creating a custom search for a specific post type

To enable search on a custom post type archive, I use the pre_get_posts hook. Add this code to your theme functions.php file. Here is an example of enabling search on a post type called “resource”: // Enable resource search add_action(‘pre_get_posts’,’pk_enable_resource_search’, 1000); function pk_enable_resource_search( $query ) { if ( $query->is_archive(‘resource’) && $query->is_main_query() && ! is_admin() ) … Read more

Rewrite rule to prettify two $_GET variables while in a new endpoint from a page

I think you are using endpoints incorrectly. When a endopoint is created, a new rewrite rule is created using a query var with the same name of the endpoint; its value is taken from the string that follows the endpoint definition. So, if you register “my-endpoint” and build this URL: /page-slug/my-endpoint/123/some-string The endpoint is passed … Read more

Automatic post deletion

You can improve by storing the “expiry” time of post as a meta instead of the publish time. This way you can query for posts with meta which is smaller then the current time and draft them, no need to loop over all posts. Drawback is that you will have to decide how to handle … Read more

Multiple Loops Inside a Function

the permalink and post title won’t be available until after you’ve run the query. the following should return the last 3 posts from the designated category. the same post is being displayed 3 times because it doesn’t look like you’re setting the permalink or post title from within “the loop” if (!function_exists(‘get_posts_menus’)): function get_posts_menus($category_name, $count) … Read more