Perform a wpdb->query on every new post submission
I want to perform a wpdb->query command every time I submit or update a post, is there a way to achieve that ?
If you wonder – but explaining WHY would be too long, I’ll just say there’s a good reason for it in my case -, I want to have this SQL command ran to replace relative hyperlinks with absolute hyperlinks :
UPDATE wp_posts SET post_content = REPLACE ( post_content, '../', 'http://www.mywebsite.net/');
So, I want to have wordpress run, every time I update a post (since wordpress has that “bad” – in my case, haha – habit of resorting to relative hyperlinks), this :
$wpdb->query( " UPDATE wp_posts SET post_content = REPLACE ( post_content, '../', 'http://www.myblog.net/'); " );
At the moment, I’m manually running this in phMmyAdmin once per day.
It just struck me that I might save it to a php file to run from an URL since phpMyAdmin allows to get a php code version (brutal discoveries of things obvious to everyone else since long ago, I call that “nero burning ROM moments” 😉 ).
But, ideally, the very best would be to have wordpress perform the SQL query itself every time it is needed.
Would you know how to achieve it, to make wordpress run this wpdb->query, every time I update or publish a blog note ?
Thank you very much if you can help ! 🙂
- The topic ‘Perform a wpdb->query on every new post submission’ is closed to new replies.