How to delete post if view-count y
-
I want automatically delete post if after a period of time, the post view count is lower than a given number but i don’t know more about php So i hope someone can help me!
Here is what i figured out:
[ Moderator note: Code fixed, please wrap code in backticks or use the code button. ]
function del_post($post_id=0) { $count = 0; $post_id = !$post_id ? get_the_ID() : $post_id; if ($post_id) { $meta_count_key = 'my_views_count'; $count = get_post_meta($post_id, $meta_count_key, true); if ($count == '') { delete_post_meta($post_id, $meta_count_key); add_post_meta($post_id, $meta_count_key, '0'); } $count = intval($count); } if ($count < 10) { $post_date = strtotime($post->start_date); if(((time() - $post_date) > (7 * 24 * 60 * 60))) { wp_delete_post($post->ID); } } }
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘How to delete post if view-count y’ is closed to new replies.