admin管理员组文章数量:1127659
I have a cpt called "movie", and I set a target for writers to make 50,000 posts in 6 months. The question is... can I make a percentage of the results of the number of recent posts against the target, and how to display it through a shortcode?
For example: "total posts are 50% of target."
Is there any way to display that with a shortcode? Please help.
I have a cpt called "movie", and I set a target for writers to make 50,000 posts in 6 months. The question is... can I make a percentage of the results of the number of recent posts against the target, and how to display it through a shortcode?
For example: "total posts are 50% of target."
Is there any way to display that with a shortcode? Please help.
Share Improve this question asked Dec 22, 2023 at 18:19 Tuagapat ManamTuagapat Manam 415 bronze badges 5 |1 Answer
Reset to default 1Here are my thoughts, which include both a shortcode and a direct function to display the post progress in the WordPress dashboard/admin area:
Creating a Custom Shortcode:
You can create a custom shortcode to display the post progress on your WordPress site using the following code:
function post_progress_shortcode() { $post_type = 'movie'; $target_count = 50000; // Set your target post count here $args = array( 'post_type' => $post_type, 'post_status' => 'publish', ); $query = new WP_Query($args); $post_count = $query->found_posts; if ($post_count > 0) { $percentage = ($post_count / $target_count) * 100; $percentage = round($percentage, 2); // Round to 2 decimal places return "Total posts are {$percentage}% of the target."; } else { return "No posts found."; } } add_shortcode('post_progress', 'post_progress_shortcode');
Usage: You can use the
[post_progress]
shortcode anywhere in your content to display the progress. This will allow you to display these statistics on the frontend of your website wherever you like.Function for Dashboard/Admin Area:
If you want to display the post progress directly in the WordPress dashboard/admin area, you can add the following code to your theme's
functions.php
file or a custom plugin file:function display_post_progress() { $post_type = 'movie'; $target_count = 50000; // Set your target post count here $args = array( 'post_type' => $post_type, 'post_status' => 'publish', ); $query = new WP_Query($args); $post_count = $query->found_posts; if ($post_count > 0) { $percentage = ($post_count / $target_count) * 100; $percentage = round($percentage, 2); // Round to 2 decimal places echo "<p>Total posts are {$percentage}% of the target.</p>"; } else { echo "<p>No posts found.</p>"; } } // Hook the function to display in the dashboard function add_post_progress_dashboard_widget() { wp_add_dashboard_widget( 'post_progress_widget', 'Post Progress', 'display_post_progress' ); } add_action('wp_dashboard_setup', 'add_post_progress_dashboard_widget');
This will add a widget titled "Post Progress" to the WordPress dashboard displaying the progress.
Now you have two methods to display post progress, one as a shortcode for content and the other as a dashboard widget for the admin area. You can use either method depending on your preference.
本文标签: Display the progress of post achievement with percentage against target in wordpress dashboard
版权声明:本文标题:Display the progress of post achievement with percentage against target in wordpress dashboard 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736706028a1948682.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
movie
posts created in the last 6 months when there are going to be tens of thousands of posts that will be problematic – Tom J Nowell ♦ Commented Dec 22, 2023 at 19:13$percentage = ( $found_posts / $target_posts ) * 100;
– Tom J Nowell ♦ Commented Dec 28, 2023 at 12:48