To count the number of posts in the given query, you can use the WordPress function wp_count_posts() after executing the query. Here's an example of how you can modify the code to count the posts: \n\nphp\n$query = new WP_Query($data);\n\nif ($query->have_posts()) {\n $count = $query->post_count;\n\n while ($query->have_posts()) {\n $query->the_post();\n qq_get_template_part('product', 'grid');\n }\n\n qq_paginator(get_pagenum_link());\n\n wp_reset_postdata(); // Reset the query to its original state\n}\n\necho 'Total Posts: ' . $count;\n\n\nIn this example, the $count variable stores the total number of posts in the query. After the loop, you can output this count using echo 'Total Posts: ' . $count;. Additionally, wp_reset_postdata() is called to reset the query to its original state.


原文地址: https://www.cveoy.top/t/topic/po2A 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录