Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action(
- 'admin_init',
- function () {
- if ( 'jnews' === $_GET['page'] && 'documentation' === $_GET['path'] ) {
- $args = array(
- 'post_type' => 'post',
- 'posts_per_page' => -1,
- );
- $query = new WP_Query( $args );
- if ( $query->have_posts() ) {
- while ( $query->have_posts() ) {
- $query->the_post();
- $post_id = get_the_ID();
- $category = jnews_get_metabox_value( 'jnews_primary_category.id', null, $post_id );
- if ( empty( $category ) ) {
- $categories = array_slice( get_the_category( $post_id ), 0, 1 );
- if ( ! empty( $categories ) ) {
- $category = array_shift( $categories );
- $category_id = $category->term_id;
- update_post_meta( $post_id, 'jnews_primary_category', array( 'id' => (int) $category_id ) );
- }
- }
- }
- wp_reset_postdata();
- }
- }
- }
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement