Skip to content

Instantly share code, notes, and snippets.

@woodwardtw
Last active February 23, 2023 17:45
set the page count in wp_options
<?php
//UPDATE wp_options with page count
function wmps_page_count(){
$page_count = wp_count_posts('page')->publish;
if ( get_option( 'wpms_data_pages_count' ) !== false ) {
update_option('wpms_data_pages_count', $page_count);
} else {
add_option('wpms_data_pages_count', $page_count);
}
}
add_action( 'transition_post_status', function ( $new_status, $old_status, $post )
{
if( 'publish' == $new_status && 'publish' != $old_status && $post->post_type == 'page' ) {
wmps_page_count();
}
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment