Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function setPostNumbers() {
- /* numbering the published posts: preparation: create an array with the ID in sequence of publication date, /
- / save the number in custom field '_post_number' of post with ID /
- / to show in post (within the loop) use <?php echo get_post_meta($post->ID,'_post_number',true); ?>
- / alchymyth 2010 */
- global $wpdb;
- $querystr = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' ";
- $pageposts = $wpdb->get_results($querystr, OBJECT);
- $counts = count($pageposts)+1 ;
- if ($pageposts):
- foreach ($pageposts as $post):
- setup_postdata($post);
- $counts--;
- add_post_meta($post->ID, '_post_number', $counts, true);
- update_post_meta($post->ID, '_post_number', $counts);
- endforeach;
- endif;
- }
- add_action ( 'publish_post', 'setPostNumbers' );
- add_action ( 'deleted_post', 'setPostNumbers' );
- add_action ( 'edit_post', 'setPostNumbers' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement