Bulk publish Pressbooks Glossary Terms

I’ve been working on an OER textbook project for some number of years. It is in Pressbooks.

The latest issue has been that the textbook was imported to the grant provider’s site and for some reason the glossary terms are all set to private. There is no bulk edit option to publicize them and there are 392 glossary terms.

I don’t know that we’ll end up with access to the database, but if we do, this is how we could fix this.

First I found the glossary terms. They’re in the posts table with the other content as you’d hope (but maybe not expect). Kindly, they are identified in the post_type column as `glossary`. That means we can easily get all of them. The post_status column needs to be changed from `private` to `publish`.1

So to do that in MySQL, we’d do the following. Which is pretty nice and simple.

UPDATE `wp_3_posts` SET
`post_status` = 'publish'
WHERE `post_type` = 'glossary';

If we had to do it in PHP, we’d do something like this. That runs once and you can delete it. I tied it to a shortcode just to make it easier to mess with if you wanted to var_dump things.


function fix_terms(){
   $args = array(
   'post_type'=> 'glossary',
   'post_status'=> 'private'
   );

   $the_query = new WP_Query( $args );//get all the private glossary terms

   // The Loop
   if ( $the_query->have_posts() ) :
   while ( $the_query->have_posts() ) : $the_query->the_post();
     // Do Stuff
     $post_id = get_the_ID();
     $fix = array(
           'ID' => $post_id,
           'post_status' => 'publish',
          );
          wp_update_post( $fix, true ); //update them to publish
   endwhile;
   endif;

   // Reset Post Data
   wp_reset_postdata();
}


add_shortcode( 'gloss-fix', 'fix_terms' );

1 The “ marks are just provided to help you see the term better. They would NOT be written in the database. I always used to struggle with stuff like that when I was learning programming things.

Leave a Reply