Sequential Custom Post Numbering
-
Hi
Does anyone know how to sequentially order custom posts by number such as 01, 02, 03, 04 etc and also be able to order these by menu_order?
I found a great post here:-
and the following looks like it would have worked for posts:-
function updateNumbers() { /* numbering the published posts, starting with 1 for oldest; / creates and updates custom field 'incr_number'; / to show in post (within the loop) use <?php echo get_post_meta($post->ID,'incr_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 = 0 ; if ($pageposts): foreach ($pageposts as $post): $counts++; add_post_meta($post->ID, 'incr_number', $counts, true); update_post_meta($post->ID, 'incr_number', $counts); endforeach; endif; } add_action ( 'publish_post', 'updateNumbers', 11 ); add_action ( 'deleted_post', 'updateNumbers' ); add_action ( 'edit_post', 'updateNumbers' );
But it doesn’t seem to work for custom posts?
Can anyone advise / help please?
Thanks
Glennyboy
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Sequential Custom Post Numbering’ is closed to new replies.