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 WordPress, you can use the
WP_Queryclass to query the database for posts with that specific tag. Here's an example of how you can do this in your theme'sfunctions.phpfile:phpfunction get_total_posts_by_tag_shortcode($atts) { // Extract shortcode attributes $tag = shortcode_atts( array( 'name' => '', // Default tag name ), $atts ); // Query the posts with the specified tag $args = array( 'tag' => $tag['name'], 'posts_per_page' => -1, // Retrieve all posts with the tag ); $query = new WP_Query($args); // Return the total number of posts with the specified tag return $query->found_posts; } add_shortcode('total_posts_by_tag', 'get_total_posts_by_tag_shortcode');
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.