Monthly Archives: September 2013

You are here: Home . Archive

Life is grim but hope is still alive

This column is generally about the sunny side of things. The new spin to old things. The “we could also look at it this way” side. The one that makes you hold the newspaper closer, squint and re-read the sentence, all the while wondering whether there isn’t a law against keyboards bringing to life such sentences. The “fall on the floor laughing then get up to call the whole neighbourhood to share the joke only for them not to get it” kind of thing. Life is heavy, let’s lighten up here. At least that’s what the columnist thinks to himself.

After a week like this though, this columnist’s keyboard, undoubtedly like many around East Africa, isn’t moved to lighten things up. It is a sad time when the terror you see acted out ever so professionally in movies hits so close to home. When the blood and gore that flashes across the screen as you crunch popcorn is seen in pictures posted by your friend on Facebook. When we aren’t looking to Denzel Washington to give us a good ending before the 90 minutes we paid for are done but to the Kenyan police, the one we know more for kitu kidogo-corruption. When the death toll is rising by the hour. When the middle-aged man who left home to go shopping with his two children finds himself trapped by armed men. They will have to jump over dead bodies to escape. What kind of trauma are those children going to go through? The young lady, fighting for her life now, whose only worry earlier was whether James really likes her seeing as he is late for their date and has not called!

One of the natural reactions is to ask questions and where facts and figures fail, our experts have theories. Then we name how many of the people killed were foreigners.

Anger also kicks in. Track them down, make them pay, kill them!

Then fear. Should I go out tonight? I can’t shop there anymore. What’s in that bag? Security checks go into high gear everywhere.

In the midst of that, a young minister here says that indecently-dressed women deserve to be raped. Emphasis on young because old ministers in ill-fitting suits hardly shock us anymore.

It is a sad time. Life is heavy. This columnist thinks a lot more about the afterlife now. And about legacy.

WordPress Tutorial: Update all posts at once

WordPress only allows you to update certain fields (like author, status, tags) for several posts at once from the admin section of your site. What do you do though if you’d like to update fields the WordPress admin section won’t allow you to? What happens if, for example, you’d like to change the post titles of all posts in a particular category? This can be done using a bit of code I’ll walk you through here.

Update 08/08/2015: Changed the code based on feedback

If, for example, you’d like to add a prefix ‘Post Prefix’ to every post in category with ID x, you’d use the following code:

        $posts_to_update = get_posts('cat=x&showposts=1000');//Retrieve the posts you are targetting
        foreach ( $posts_to_update as $update_this_post ):
            $update_this_post->post_title = 'Post Prefix: '.$update_this_post->post_title;//The post field you are updating.
            wp_update_post( $update_this_post );

Replace ‘x’ with the ID of the category you’d like to update. ’1000′ is the number of posts we’d like to update; change it to what works for you

Using this technique, you can update any field (post title, authors, category, etc) of your posts in bulk at a go. Modify the code above to suit your needs by changing:

1. The get_posts

This is what determines which posts you’d like to update in bulk. In the example above, we targeted posts in a category with ID x (cat=x) and we restricted it to the first 1000 posts (&showposts=1000). Change this according to which posts you’d like to update. A full list of parameters you can use and a few examples are shown here

e.g. to target posts by author ‘user_nicename‘:

$posts_to_update  = new get_posts( 'author_name=kakoma' );

More on get_posts() here: get_posts() details

2. The $post_update_array

This is the next bit you’ll need to update. Change this to match what field you’d like to update. In the case above, we are updating post titles so we modify $update_this_post>post_title by adding ‘Post Prefix’ to the current title. You can modify content, author, etc in the same way. All you need to know is the field name.

e.g. To modify your content instead, replace:



$update_this_post->post_content = $update_this_post->post_content.' Awesome suffix added to every post';

For a full list of the fields you can modify, check here

Changes to code are done. On to…

Where to put the code

There are very many places this code can be put. In functions.php in your theme, in a plugin, in a template…putting it in a plugin though is the most appropriate way of doing things. To do this, we’ll need to add a bit more code above the lines we’ve discussed. Use this:

  * Plugin Name:       Post Bulk Update
  * Description:       On activation, I'll updates certain fields of your posts at once. Can't wait!
  * Version:           1.0.0
  * Author:            Your name here
  * License:           GPL-2.0+
  * License URI:
  *  */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly 

if ( ! class_exists( 'MyPlugin_BulkUpdatePosts' ) ) : 

class MyPlugin_BulkUpdatePosts {          

public function __construct(){
      register_activation_hook( __FILE__, array( $this, 'do_post_bulk_update' ) );//Run this code only on activation

//Put your code in this function
public function do_post_bulk_update(){
    $posts_to_update = get_posts('cat=x&showposts=1000');//Retrieve the posts you are targeting
    foreach ( $posts_to_update as $update_this_post ):
           $update_this_post->post_title = 'Post Prefix: '.$update_this_post->post_title;//The post field you are updating.
           wp_update_post( $update_this_post );


return new MyPlugin_BulkUpdatePosts();

Put this code in a file (e.g. post_bulk_update.php), put that file in a folder, zip that folder and upload it as a plugin (Instructions here). You’ll see a plugin named ‘Post Bulk Update’. On activating the plugin, your changes will be made. Delete the plugin after use.

Let me know if you run into any issues….or if it works for you.

Advice on graduating to university

Dear reader-who’s-going-to-join-university-very-soon, it is time to rejoice. Out with the shackles of wearing a school uniform to class; in with going to class in a durag, heavy jeans, an oversized T-shirt and beat-down flip-flops. A resounding boo to attempting to meet all your body’s nutritional requirements by eating posho and beans, hooray to the miracle that is rolex and Mama Nalongo’s lukumi lukumi food. Goodbye to studying things you can’t possibly see practical use for in your foreseeable future (sines and cosines anyone?). Adios to queuing up to take a shower. The bad days are over. It is time to be on first name terms with every waiter in every upscale hangout in the city. “Hi John, will it be the same today? Shaken AND stirred? Ok. Coming right up”

The reality might be slightly different though. Chances are, you are still going to learn a lot of stuff you may not see practical use for in your foreseeable future (like how to wind a transformer, or what’s the speed of an electron). The point though, I feel, wasn’t really to show you how unsettled an electron is (electrons are very small things that can’t sit still and they are the reason we have electricity) but more to open your mind to exploring; to appreciating the unseen (I don’t see my editor holding a whip and issuing instructions but I know I have to deliver this article). Winding the generator was the scapegoat; what they really were teaching was that sometimes you have to sit through a few not-too-pleasant things (cutting frogs open, climbing a telephone mast) to get to your goal, your promised land. You’d have to sit through the study of manure and its illustrious history (and pass the exam about it) to get to the cooking lessons you love. So it is with life.

You are probably still going to eat posho and beans every so often because being able to battle being broke in secondary school is like being the master at fighting cats in your village not knowing that there are lions out there. Being broke at university is a bigger cat. Leaner, meaner, stronger, more lethal. Still a cat so the lessons you learned earlier aren’t entirely useless but you need a few more tactics before you can stand.

What about living on the edge and shucking all responsibility? We’ll always make jokes the extremes even when we age and grey. Don’t be the butt of all those jokes.

How to alter WordPress default comments widget

WordPress ships with a nifty widget to show your most recent comments. There are a number of ways to modify it

  1. Use a plugin and change everything
  2. Copy the widget code from wp-includes/default-widgets.php into your theme’s functions.php and tinker away
  3. Use the widget_comments_args filter

I’m not big on plugins. Option 3 is pretty clean and light and it’s what I’ll explain here.

In your theme, open functions.php and paste this:

function mythemename_alter_comments( $args )
$args = array( 'number' => 5, 'status' => 'approve', 'post_status' => 'publish' );
return $args;
add_filter( 'widget_comments_args', 'mythemename_alter_comments', 10, 1 );

Replace ‘mythemename’ with your theme name. Change the values in

array( ‘number’ => 5, ‘status’ => ‘approve’, ‘post_status’ => ‘publish’ )

to suit your needs

For the full list of parameters you can use (and their default values), read this

Use this method if you want to get your recent comments but don’t want to go through the hustle of styling them. Naturally, another option is to use the get_comments function and style everything

For Facebook and my country

In a recent report released by Facebook showing governments that had requested for user account information of some of its citizens in the first six months of this year, we were named. Our very own government of Uganda, the one we know and love, this one here, it made it into the report. We don’t just win gold medal after gold medal, we make it into reports from Facebook.

In this columnist’s mind, the only proper way for a nation to celebrate is by declaring a public holiday, so, let’s declare a public holiday. Joy all around. Cheer and goodwill. Spontaneous somersaulting on the streets everyone. Dance competitions on every corner.

This is big dear reader. First off, it means that our beloved government uses computers. Computers that work. Computers that aren’t old, with fat, off-white monitors that need to be slapped to flicker to life. Computers that aren’t loud enough for people in the next building to think that there’s an explosion every time you hit ‘Save’ and the PC starts processing your request. Computers with internet. Internet that works. Internet that works long and fast enough for you, the government worker, to open a Facebook page, choose to create a message, type out the message and send it to the US requesting for information about another Facebook user.

The report from Facebook goes on to say that our government requested that Facebook provide the user information of one person. The jury is still out on who it is. Is it Stephen Kiprotich? Did they, by any chance, want to look through his likes and get a better picture of the things he is into so that they’d get him an awesome gift he’d love? Is it Elias Lukwago? Did they want to look through the non-public photos he was tagged in? The groups he is in? The posts he comments ‘lol’ on? Is it a leader of the opposition? Did they want to know his birthday so that they do everything to ruin it?

There are other ways to get all this information without going through all the trouble of requesting Facebook. For one, they could walk up to the person, be nice to them, pamper them, take them for a government massage, state steam bath, four course meal, all those fancy things and then ask them for their password.

Settling disagreements through the ages

Two prominent politicians have recently been in the media, going back and forth, sending each other not-too-friendly words. Politician words. One is a guy. He is smooth-talking and doesn’t wear ill-fitting suits in front of cameras. The other is an iron-lady. She goes by the book.

The feud, fought out entirely in the media, has become more and more heated. Dear reader, you may see this and think that things have always been this way. This columnist is all for researching and bringing you the truth every Sunday. Feuds have not always been settled in the media. Presenting, the different ways that disagreements have been settled through history

Gun fights
Back in the day, in the Wild West, disagreements were settled by gun-slinging. The two disagreeing parties, after trading insults to their heart’s content, would decide that the only way for the argument to be truly settled was if one of them got some lead into their system. By lead I refer, every so underhandedly, to a bullet. By a bullet I refer to one shot from a gun. One party would stand at one end of a road, the other at the other end and on the count of three, they’d draw their guns and shoot.

Wrestling (Ekigwo)
Closer to home, some disagreements were settled by tussling it out till the back of one of the parties touched the ground. It was usually messy; teeth were lost, garments torn, scars and egos bruised and mainly served to greatly entertain crowds. It is said that given the innate thrill that comes with watching grown folk act like beasts, in time, this form of settling disagreements took on a professional form and several forms of entertainment were crafted around it; gladiator fights, Obi Okonkwo’s conquests, ekigwo ekiganda, wrestling, the list is exciting.

Ask the king
This form was usually a reserve for more refined folk; in a jungle, hyenas wouldn’t have this as an option but leopards would. Given the nature of our combatants in this case, this would be the ideal solution. To enter the king’s presence though, one had to go with all kinds of offerings before pleading their case, painting how bad a human being the other party truly is. Seeing as our saga is not yet done, let’s wait and see