Last active
February 23, 2023 17:45
-
-
Save woodwardtw/7ab623d8db9ea8d9f0489b17f046022a to your computer and use it in GitHub Desktop.
set the page count in wp_options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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