Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
2  
@Downloadtaky: I can understand you don't want to force your users to do the conversion from bbCode to HTML, but why do you want to do this in a cron job? Did you know that there are also filters that execute when a post is created, so you can write code that will always convert bbCode to HTML when a new post is written? –  Jan Fabry Apr 7 '11 at 9:42
    
@Jan Fabry I have already a plugin that converts bbCode to html but it doesn't modify the post it only reads [img][/img] tags and "parses" (is it the corrected way to say it???) it so if you inspect the code you see '<img src' instead but I need the code to be modified in order to use catch the first image properly. –  Downloadtaky Apr 8 '11 at 10:14
1  
@Downloadtaky: Yes, there are two main ways these plugins can work: either they take the database content and convert it to HTML every time the post is displayed, or they take the editor content and convert it once to HTML and store this in the database when you save the post. What is the name of the plugin you use? It is probably possible to convert it from the first to the second type. –  Jan Fabry Apr 8 '11 at 10:18
    
@Jan Fabry WP BBCodes to HTML Parser = xblurb.com/wp-bbcodes-to-html-parser –  Downloadtaky Apr 8 '11 at 10:44
1  
@Downloadtaky: If you don't mind that all bbCode will be replaced by HTML (so when you re-edit a post you will get HTML instead of bbCode, but you can still add new bbCode), you can replace the the_content at the last line of that plugin with content_save_pre. This means that you don't do the conversion every time you show the post, but only once right before you insert it into the database. You then still need to update the existing posts once - but you don't need a cron job for this. Perhaps you should ask a new question for this. –  Jan Fabry Apr 8 '11 at 12:21
show 2 more comments

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
add comment

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).

share|improve this answer
    
I'm a noob in sql stuff could you please be more specific? Using the query I gave you what have I to do? Have I to create a php file? –  Downloadtaky Apr 7 '11 at 1:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.