gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
how to get total number of post in specific tag name in functions.php my tag name is…
- User
how to get total number of post in specific tag name in functions.php my tag name is 4k-live-wallpapers-2160p i need it with short code
- Assistant
To get the total number of posts in a specific tag name in your WordPress theme's
functions.phpfile using a shortcode, you can use the following code:codefunction get_tag_post_count($atts) { $atts = shortcode_atts(array( 'tag' => '', ), $atts); $tag = $atts['tag']; $args = array( 'tag' => $tag, 'post_type' => 'post', 'posts_per_page' => -1, ); $query = new WP_Query($args); $count = $query->post_count; wp_reset_postdata(); return $count; } add_shortcode('tag_post_count', 'get_tag_post_count');Then, you can use the following shortcode in your WordPress posts or pages:
code[tag_post_count tag="4k-live-wallpapers-2160p"]This will display the total number of posts associated with the "4k-live-wallpapers-2160p" tag.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.