Joe Casabona

Developer, Author, Nerd

July 24th, 2014

Win a Signed Book or Other Great Prizes!

This week I rolled out a new design for Responsive Design with WordPress’s site. I decided that on top of the site starting to feel a little stale, there wasn’t a whole lot of information about the book aside from a little blurb. I added a bit more that will hopefully give visitors a better idea of what the book is about and what others think about it. Because of this, I want to celebrate by doing the biggest giveaway I’ve done.

Read the rest of this entry »

July 23rd, 2014

Quick Tip: Check to See if a Slug Exists in WordPress

Recently I was doing some work where I was importing RSS entries into a Custom Post Type in WordPress. Since there were no common IDs between the feed and WordPress, to prevent duplicate entries I tried comparing titles. This also proved to be an issue as titles aren’t always unique, and they weren’t in this case. I settled on comparing slugs; WordPress creates a unique slug for each post from the title, and there’s a way to know what that slug is going to be before the post is added.

Assuming that our RSS entries are in an Object called $item, we do this to get the slug:

$title= wp_strip_all_tags($item->title);
 $slug = sanitize_title($title);

The first function will remove all HTML tags from the title that was passed in; it was unclear if the next function, sanitize_title(), did that, so I took the extra precaution.

sanitize_title() is where the magic happens. It takes a now HTML-less string and converts it to a string that can be used in URLs; this is the would-be slug. You can then pass that slug to this query to see if a post with this slug already exists:

$post_if = $wpdb->get_var("SELECT count(post_title) FROM $wpdb->posts WHERE post_name like '".$slug."'");

If $post_if is < 1 at this point, the post doesn’t exist. Do with it what you will! If that’s the specific slug you want to use, you can also add it to the post array like this(assuming you’re using $post_array):

$post_array['post_name'] = $slug;

And there you have it! Feel free to comment your thoughts, improvements, and clarifications.

July 21st, 2014

New Blog on How to be Distraction Free: Uninterrupt.Me

Over the weekend I happened to be awake and in front of a computer when I came across this tweet from @jenseninman, where she mentioned that she had 2+ hours of uninterrupted time to work on the amazing @CenterCentre project. This got me thinking that it’s been a while since I had some solid time to myself, uninterrupted and distraction free. I also thought that a dedicated blog for how to becoming distraction free seemed like a good idea. When I looked, the (amazing) domain was available. What was I supposed to do?

Read the rest of this entry »

July 16th, 2014

My Everyday Things, Part 1: Workflow

Recently I started following Everyday Carry, a blog dedicated to showcasing the items that people must have on an everyday basis. I decided that in an effort to blog more, I would do a short, 3 part series on the stuff I use everyday. The series will be broken up into 3 parts: today’s installment is Workflow, then Carry/Misc, then Home Setup. Let’s jump in!

Read the rest of this entry »

July 11th, 2014

The Right Way to Explain Your Freelancing Career to Your Dad

Earlier this week I read an article offering advice on how to explain your freelancing career to your dad. It’s something a lot of young people, including myself, struggle with. However after reading the article, my thoughts were less than flattering. Not only was it bad advice, it was a demonstration of what not to do if you’re serious about a freelance career. If you’re really interested in reading the article, I will link it at the bottom. For now, here’s what I consider the right way to explain your freelancing career to your dad (or mom, or whomever).

Read the rest of this entry »