Use Cron to modify posts via sql

Hi to all I need to run this twice a day:

UPDATE wp_posts SET post_content = REPLACE ( post_content, '[img]', '<img src="' );
UPDATE wp_posts SET post_content = REPLACE ( post_content, '[IMG]', '<img src="' );
UPDATE wp_posts SET post_content = REPLACE ( post_content, '[/img]', '" />' );
UPDATE wp_posts SET post_content = REPLACE ( post_content, '[/IMG]', '" />' );
UPDATE wp_posts SET post_content = REPLACE ( post_content, '[b]', '<strong>' );
UPDATE wp_posts SET post_content = REPLACE ( post_content, '[B]', '<strong>' );
UPDATE wp_posts SET post_content = REPLACE ( post_content, '[/b]', '</strong>' );
UPDATE wp_posts SET post_content = REPLACE ( post_content, '[/B]', '</strong>' );

How can do it? I don’t want to run it manually and I can’t do it each time a post is published because I’m running a MU website and my authors are too lazy to modify their code from bbCode to HTML.
I’m using cPanel so I can add a CronJob easily if you teach me how to do it.
Thanks to all!

Related posts

Leave a Reply

2 comments

  1. Creating your own schedules is a little messy (because they need to be persistent and stored in database), but it is quite easy to hop on one of the native schedules that run twice a day.

    add_action( 'wp_version_check', 'my_function' );
    
    function my_function() {
    
        //stuff
    }
    

    As for running actual queries you should use $wpdb for that.

  2. You can create a php file that includes wp-load.php like this:

    require_once(wp-load.php');
    global $wpdb;
    

    Once you do that you have access to anything in wordpress, including the database object so you can execute queries using $wpdb->query();

    You can just load that file via cron (you probably have to wget the URL via the webserver).