Count post meta entries

WP_Query has a property that returns the no of posts that match your query. You can print it as follow in your first try: $query = new WP_Query( $args ); echo $query->post_count;

Avoid removing duplicate posts

It’s a bit less efficient, but if you have an array of IDs, possibly including duplicates, and want to get the posts for each, I’d suggest use get_post() on each ID, giving you an array of posts. $post_ids = [ 24, 11, 60, 11 ]; $posts = array_map( ‘get_post’, $post_ids ); global $post; foreach ( … Read more

Update wp_query every week

I see two approaches: via cron job… or website / page cache which lasts 1 week. In case you want to do the cache option: you just need to add ‘orderby’ => ‘rand’ to your WP_Query and install a caching plugin for your page, then set it up for 1 week. CronJob: you need to … Read more

How can I re-query post_type and rewrite the url?

I think you need to first define property_com_listing_type as a query: https://codepen.io/the_ruther4d/post/custom-query-string-vars-in-wordpress Then you can rewrite the urls with add_rewrite_rule (do not forget to save permalinks after change): https://codex.wordpress.org/Rewrite_API/add_rewrite_rule with a regex like ^category/([^/]+)/([^/]+)/? Then you can modify the query using pre_get_posts: https://developer.wordpress.org/reference/hooks/pre_get_posts/

Get unique post by meta value using wp_query

You can simply limit the query to return only one result. To achieve this, use the field posts_per_page in your query arguments. Check the documentation for more info on this. $args = [ ‘cat’ => ’44’, ‘posts_per_page’ => ’16’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘meta_query’ => [ ‘metavalue1’ => [ ‘key’ => ‘Meta_value’, ‘value’ … Read more