Skip to content

Instantly share code, notes, and snippets.

@woodwardtw
Last active February 23, 2023 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woodwardtw/7ab623d8db9ea8d9f0489b17f046022a to your computer and use it in GitHub Desktop.
Save woodwardtw/7ab623d8db9ea8d9f0489b17f046022a to your computer and use it in GitHub Desktop.
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