Event Date Sorting Columns for WordPress CPTs

On a recent client project, one of the requirements was adding a couple admin columns for a custom pst type type to sort things by start date and end date.

It was a slight faff to work out how this should be done, so I’m plonking it here for me to find in the future.

Columns

The complication here was wanting to show the date in a human-readable format whilst letting the sorting happen using the unix time stamp.

So, a few things to note:

  • event is the custom post type name. If it were cake, every action and filter name would need to be cake instead of event.
  • first_show_date and last_show_date are custom fields storing the Unix time stamp

Add a column to the admin

function event_cpt_add_columns($defaults) {
  $defaults = array(
    'cb'             => '<input type="checkbox" />',
    'title'          => 'Title',
    'firstshowdate'  => 'First Show Date',
    'lastshowdate'   => 'Last Show Date',
    'date'           => 'Date',
  );

  return $defaults;
}

Add something to that new column

function event_cpt_column_data($column_name, $post_ID) {
  if ($column_name == 'firstshowdate') {
    echo date('jS F Y', get_post_meta('first_show_date', $post_ID), true);
  }
  if ($column_name == 'lastshowdate') {
    echo date('jS F Y', get_post_meta('last_show_date', $post_ID), true);
  }
}
add_filter('manage_event_posts_columns', 'event_cpt_add_columns', 10);
add_action('manage_event_posts_custom_column', 'event_cpt_column_data', 10, 2);

function event_cpt_register_sortable($columns) {
  $columns['firstshowdate'] = 'firstshowdate';
  $columns['lastshowdate'] = 'lastshowdate';
  return $columns;
}
add_filter("manage_edit-event_sortable_columns", "event_cpt_register_sortable" );

Enable sorting…

… using the original value of the custom field, not it’s formatted counterpart.

function event_cpt_orderby( $query ) {
  if (!is_admin())
  return;

  $orderby = $query->get('orderby');

  if ('firstshowdate' == $orderby ) {
    $query->set('meta_key','first_show_date');
    $query->set('orderby','meta_value_num');
  }

  if ('lastshowdate' == $orderby ) {
    $query->set('meta_key','first_show_date');
    $query->set('orderby','meta_value_num');
  }
}
add_action('pre_get_posts', 'event_cpt_orderby');

If this can be improved, do let me know!

June Update

It’s almost exactly six months since I wrote anything here. That’s largely due to me not having anything interesting to say, or interesting enough to share anyway. But a lot has happened in six months, so an update post on lots of little things may be interesting, or at least interesting for me to look back on.

Me

The #60lbsswap thing seems to have fizzled out, I was shit at keeping up with it anyway. I’d never put weight on, just fluctuate a few pounds each week. Nothing ever stayed.

With that said, I have been making more of an effort to eat with more regularity – I had breakfast today! I’ve also been using some old weights to (very) slowly building some muscle. I accepted the fact I’ll never have a beach body1, I’ll always be skinny and most clothes won’t fit me in a flattering way. But I can do something to help, if only a little.

I’ve also been keeping up with applying Minoxidil to my jaw, in an effort to help fill a patch where very little hair has grown. It only bothers me because it is right on the jaw line, and looks like I slipped with the razor if I don’t keep it trimmed. I’d love a full beard for our wedding in 2018, and it looks like beard growing takes fucking ages!

Another thing I’ve been notoriously shit with is sleep. Granted, I write this at 1am on a Wednesday, but months ago that would mean not waking up till linch time. These days I can wake up around 9am/10am and feel okay. It’s not the best scenario, but it’s a lot better than it was, and it steady progress in the right direction.

Work

Cross Stroke is going well. I have enough work booked up until October to keep me warm and occupied. From May 2015 to May 2016, I earnt more than I would’ve if I stayed at Ghost on the same salary, and this year (May 2016/17), I have a wages strategy that is relatively easy to maintain and means money can start building up in the business for rainy days.

You can see here that money in the bank was very peaky last year, it’s now slowly starting to rise.

Money in the bank over the past year

In terms of growing the business, I’m going to maintain what I have at the moment until we’ve got a house, then I can be a little more aggressive with streamlining workflows, finding more clients like the awesome clients I have, and looking into the first hire.

Away from the financial side of things, I’ve slowly been getting better with keeping to deadlines, scheduling work properly, and keeping it all organised. Every project has a Git repo, a TaskPaper file, and time marked off in the calendar. I know it’s simple, but it’s a huge step from how I used to do things.

In the next few months, I’m going to have some branding done for Cross Stroke. No matter how many times I try to do it myself, I’m never happy with it. I’m really looking forward to having an official .eps file and brand guidelines!

House Hunting

Thanks to that mounting of cash I have in the business2, we’re one step closer to being able to buy a house. We’re a long way off yet, but with me being self-employed and the higher earner, I know whoever lends us a mortgage is gonna want to know lots about the business. Having enough cash stashed away to pay my wages for a few months is surely gonna help, if only with my stress levels.

The nest step is do all the necessary paperwork the lenders will need about my business, then re-ignite talks with a recommended mortgage advisor, see what we can borrow, then go hunting.

I’m confident we could either have moved in by the end of the year, or have done whatever needs to be done to buy a new house, because new houses come with certain financial benefits for first time buyers in the UK.3

Kodery

Remember this post from December asking what to do with it? I still have no idea. It costs nothing to keep it running, so I’ll let it sit until I have a better idea, or the inclination to do something.

Other side projects

I’d still like to re-write my WP starter theme. I know there are many, I want my own for the same reason there’s a fuck-ton of CSS libraries – the existing options don’t fit my very well.

When I find a spare week (July looks good for that), I’m going to prototype a joint venture i’m working on with a client. It’s very interesting, beautiful, and right up my street. More on that later.

Car

If you follow me on Twitter, and don’t skim past any car-related tweets4, you might remember Ford miss-ordered my black Focus ST, so, after some bitching and moaning, they let me order another, giving me a chance to change some specs.

I changed to the silver paint, larger 19” wheels (which also means better standard-fit tyres), and privacy glass. The car does look great in black, but black paint doesn’t sty black very long. I’d spend half a day perfecting the paint, then a day later, it looks like I haven’t bothered.

I event cleaned this silver car in a month (apart from removing bird shit), and it still looks alright. I didn’t choose silver an excuse to not wash it, but I’m a busy guy. I still give it the same attention, but I don’t feel embarrassed driving it ‘dirty’, like I did wth the black paint.

  1. Whatever the fuck that is… 

  2. I like to cash it out, make a throne of £50’s, rub it all over myself, then give it back to the bank. 

  3. Knowing my luck, that’s something #brexit would’ve fucked up. thannnks… 

  4. I don’t blame you, their either rants or dreams. 

2015 In Review

Like last year, this year has been good. And as ever, plenty of ups and downs.


January was a fairly quiet month.

February was also fairly quiet, except Hayley & I booked a trip to Disneyland Paris.

In March, I asked Hayley’s dad for his permission to propose, we went to Disney, and I proposed. it was lovely :)
I also left Ghost.

I spent all of April searching for my next venture, ultimately settling on going freelance again, with a forward-thinking view of starting an agency.

May was when I decided on a name for the company, and got everything legally sorted. Accountant, business bank, Companies House stuff, yada yada yada.

In June, I ordered my new car, my brother also got married – I was best man. It’s scary.

August was full of work for me, and burnout.

September saw me, Haley, and her parents fly to Nice for a week of cocktails and sun. I also picked up my new car hours after landing.

In October, Hayley & booked another trip to Disney.

In late November, we travelled to Disney again, but I drove this time. It’s cheaper, easier and more comfortable.

December, was just another normal month, aside form the couple weeks off at the end.

Other Improvements

It’s now been 17 months since I stopped smoking cigarettes, but I still vape daily. I did enjoy smoking, but I’ve lost the desire now. There’s no feeling of tabboo when someone offers me one on nights out. Through no effort, I’ve also seemingly convinced a few friends to try vaping too.

I bought some minoxidil a few months back, in an effort to help a bald patch on my chin. For a couple months, I saw no real changes, but that patch has a few dark hairs in it now, which is awesome! By the time I get through every bottle I have, I might have a non-patchy beard!

I got an Apple Watch in June, so that’s nice.

Learning to separate work and life more has been a huge benefit to me. Given I plan to work (i.e. code) 6 hours a day, it means my typically later starts to the day don’t eat into the evenings. That means my sleeping pattern can be what it wants to me, work gets done, and I have time for Hayley in the evenings – the way it should be. That doesn’t mean I’ve stopped trying to wake up earlier though – i’d still like to start the days work at 6am and be done my the early afternoon.

And lastly, I have a much stronger sense of my finances. I now control how much I pay myself, when, and where that money goes once it’s mine and not the businesses. That in itself doesn’t change much, but it enabled me to plan a bit better. If business is good for a few months in a row (and continues to look good months ahead), I can give myself a little pay rise and pipe more money into our house savings. We’d like to buy a house in 2016, and we’re getting closer each day.


Of course there’s goals for 2016.

  • Start working earlier
  • Find another design agency client who use me for all their web dev work
  • Continue with the house savings
  • Grow that beard
  • Put on some more weight
  • Pipe-dream time: Put on a little muscle

On Kodery

Kodery

I’m at a cross-roads with Kodery – I have a few options, but I don’t know what to do with it.

The last commit as almost a year ago – 18th January 2015. That’s mostly due to me having to prioritise paid work over it.

When I started building Kodery in 2009, I had a full-time job, no work-like balance sensibilities and no friends to keep be occupied – I could pour any spare time I had into it. That has drastically changed. I have a beautiful fiancée I want to spend time with, I know when to stop working, I enjoy playing pool, and driving with my friends.

I would like to keep the service running, because I have several ideas for it such as an API, embeds, better search, much-improved UI, and better permissions so it can fit much larger teams.

Ultimately, it comes down to time and money. I can only commit more time to it if it can pay its way. It’s never earnt me a penny.

This leaves me with a few options.

Option #1 – Re-work and charge

This is my favourite option.

This would involve some drastic changes throughout the code base to build in those aforementioned features.

  • A full REST API
  • Embeds (but not shitty)
  • Improved search
  • Much-improved UI
  • More extensive user permissions

It also means spending quite a lot of time building in the ability to charge. I’ve learnt that payments are really not simple – there’s so many edge-cases to consider, and this itself is going to take a lot of time. There’s also EU VAT bullshit to take into account.

Aside from that, I wouldn’t want to charge for something I’m not massively happy with, so I’d want to re-build several parts of the app, such as the underlying code that stores snippets and feeds them back to you. It’s not bad, but I’ve learnt so much in the past couple years that I know of any ways to really improve this.

Option #2 – Close it

To close it, I’d have to first build an export function, so you can export everything you’ve chucked into it over the years. Some people have hundreds of snippets, and I don’t want them do disappear as I delete the database.

After that, make final backups of the DB and code, then nuke the server.

Option #3 – Sell it

I’ve never really considered selling before, but it’s an option. I have a rough idea what I’d like to sell it for, but I’m keeping that close to my chest.

The code isn’t bad – it’s not full of glaring security holes, but I’m sure whoever bought it would have monetization in mind, and would want to build that in. I’d hope they’d want to do the same as me if I were to set it up as a paid service myself.

Help me choose

I don’t want to make any decisions without hearing form you first. Fill out the poll below to chime in. You can also email me at [email protected] if you have any thoughts. I’d like to hear anything you have to say.


The poll is now closed.

HTML Developers: Please Consider

ARIA allows developers to re-invent and extend native HTML features in meaningful ways. But like all bolt-on technologies its features are brittle compared to its built-in counterparts.

I never bothered with ARIA roles. Like I’ve thought for years, using HTML the way it’s meant to be used is better.

It’s true that it can sometimes be a pain to make form elements look and behave how you’d like them to, but in recent years, CSS has made it a lot easier to remove standard styling from form elements, and re-style them how you want. They retain their default functionality, which is almost always better than whatever someone in a decision-making position can dream up, but look how you want.

By using ‘standard’ HTML, everyone wins.

Page: 2 of 12