Post to Twitter when you post to your blog
Filed Under Twitter, Wordpress on 2008-02-25, 12:15
I don’t like doing things manually when I can have software do my bidding. Usually I’ll send a twitter when I have a new blog post on here that I think people are interested in. (I recognize not everyone has my RSS feed in their feed reader…yet) But it’s a manual process and an extra step, so I went out and found Alex King’s Twitter Tools plugin. Alex King is a name forever associated in my head with WordPress, primarily for his help in finding themes back in the early days of WP. This plugin is pretty full-featured:
- Archive your Twitter tweets (downloaded every 15 minutes)
- Create a blog post from each of your tweets
- Create a daily digest post of your tweets
- Create a tweet on Twitter whenever you post in your blog, with a link to the blog post
- Post a tweet from your sidebar
- Post a tweet from the WP Admin screens
- Pass your tweets along to another service (via API hook)
I’ve currently got it set up to send to twitter when a post goes live on here. So in theory, when this post went live, it should have shown on my Twitter page.
UPDATE: Looks like Twitter Tools will post any edits to a posts if that blog post has not been twittered yet. Sorry for the twitter flood when I removed the “Uncategorized” category from a couple old posts. I’m going to look into manually adding the “twittered” metadata to all my posts so it doesn’t happen again.
UPDATE 2: Threw together a quick little php script to update the database so old posts aren’t twittered when they’re edited. YMMV, User beware, no warranty, etc. You’ll want to make a backup of your databases, then fill in your username, password, and database_name and then run this either from command line or via the browser.
/*--------code start--------*/ mysql_connect(localhost, "db_username", "db_password"); mysql_select_db("database_name"); $res1 = mysql_query("SELECT * FROM wp_posts p WHERE (p.post_status LIKE \"publish\")"); while ($row = mysql_fetch_array($res1, MYSQL_ASSOC)) { //find out if the TwitterTools metadata has already been written $sql2 = "SELECT * FROM wp_postmeta WHERE (post_id = ".$row['ID'].") && (meta_key LIKE \"aktt_tweeted\") && (meta_value LIKE \"1\")"; print "Post ID: ".$row['ID']."
\n"; if (!mysql_numrows(mysql_query($sql2))) { //metadata not found, let's fake it without twittering $sql = "INSERT INTO wp_postmeta (post_id, meta_key, meta_value) VALUES (".$row['ID'].",\"aktt_tweeted\",1)"; mysql_query($sql); print " -- added metadata to fake it.
\n"; } else { print " -- already been twittered.
\n"; } } /*--------code end--------*/
Tagged: blogging, plugins, Social Networking, Twitter, Wordpress