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;
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;
I presume you want to get the users who registered during the last month based on their post count. Use the following code: $args = array( ‘orderby’ => ‘post_count’, // Gets the users based on the no. of posts they have made. ‘order’ => ‘DESC’, ‘role’ => ‘Subscriber’, // Gets the users with this role. … Read more
You have extra spaces around change_posts_order, inside the quotes: add_action( ‘pre_get_posts’, ‘ change_posts_order ‘ ); PHP can’t find a function with that name, because wits looking for that function preceded with the spaces. Remove the spaces to fix the issue: add_action( ‘pre_get_posts’, ‘change_posts_order’ );
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
Your query should work as is. To test this, I created 4 posts, and then using WP CLI, ran: wp post meta add 10 boxzilla_options “testingtesting123” Where post 10 is a post with the title test. 3 other posts existed that did not have the post meta. To test that the post meta key/value pair … Read more
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
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/
Why does my output of get_the_ID() change after a 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
WP_User_Query Orderby Not Working