Hello, my name is Alex Mansfield. I am primarily a freelance WordPress developer, but I occasionally work on other design and development projects.

Displaying Custom Post Types in a Custom Taxonomy Archive

The project I was working on today required a custom post type that included a custom taxonomy. Setting this up on the back end was simple. However, when I went to the front end, all the posts in the custom post type were missing from the custom taxonomy archive. Since it took me way too long to figure out the source of this issue, I’m going to document it here.

It all comes down to this poorly named setting:


When registering a post type, this setting determines whether or not your custom post type will show up in your site’s search results. However, it also has the unexpected side effect of determining whether or not your custom post type will show up on taxonomy archive pages. If you want to include your custom post type in custom taxonomy archives, exclude_from_search must be set to false:

'exclude_from_search' => false,

Note: If the “public” setting is set to “true” then the “exclude_from_search” setting can simply be removed.

Special thanks to Pieter Goosen for mentioning this issue in this Stack Exchange thread.

This issue is also mentioned in the “exclude_from_search” section of the old WordPress Codex page for registering custom post types.

  • PublishedAugust 12, 2016
  • Posted InWordpress

Migrating WordPress Multisite to a Local Development Environment

This post is primarily a reminder to my future self. However, I don’t think I’m alone in this struggle. Migrating WordPress multisite can be quite a challenge, especially if you’re migrating from a live site to a local development environment. If you’re using http://localhost as your local development environment root with individual sites placed in subfolders like I was doing, your URL structure is most likely quite a bit different than the live site you’re trying to migrate.

Some day I may write a full tutorial on how to accomplish this, but for now I just want to highlight the missing piece that I didn’t find in any other tutorials (and that I spent a few days trying to find).


WordPress Audio: Add a Download Button to mediaelement.js

So I got a call this morning asking how to download an audio file that WordPress was presenting with medialement.js. As you might have noticed, since WordPress started providing an audio player there hasn’t been an easy way to allow audio files to be downloaded as well as played. This has bothered me for a while, but this morning’s call gave me the incentive to look into it further.

My first thought was to use a custom field to store the audio file URL. Then I could display both a player and a download button based on the same URL. However, the site I was working on had years worth of audio, and I didn’t want to go through post by post and move the audio file URL out of the post editor and into a custom field. My next thought was to modify how WordPress loaded the media player and hopefully filter the output to add a download link. While this may be possible, I ended up deciding against digging into the filters in WordPress core and just used a few lines of jQuery. Here’s what did it:

// Add download links to default audio player.
$( document ).ready(function() {
	$('audio').each(function( index ) {

		var source = $(this).find('source').attr('src');

		if ( source != '' ) {
			$(this).after('<a href="' + source + '" class="audio-download" download>Download</a>');


Keep in mind you’ll need to load jQuery in order for this to run.

I just added a few lines of CSS to style the new download buttons:

a.audio-download {
	margin-top: 1em;
	background: #eee;
	padding: 0.5em 1.5em;
	border-radius: 5px;
	display: inline-block;

a.audio-download:hover {
	background: #ddd;

…and that’s it!


  • PublishedJanuary 29, 2015
  • Posted InHacks

Setting Up Ubuntu/Linux Mint for Web Development

Every so often I switch computers or reinstall my OS and end up searching around the web for the exact steps to get everything working again. Today, as I set up my OS again, I figured I might as well document the process. Since Linux Mint is based on Ubuntu, I think that these steps (at least most of them) should work for Ubuntu users as well.

1. Install the OS

There are plenty of tutorials around the web explaining exactly how to install Linux. Today I’m going to skip straight to the steps I take immediately after the OS installation in order to turn Linux into a tool for web development.

2. Install LAMP

LAMP stands for Linux, Apache, MySQL, and PHP. The first letter of the acronym (Linux) is already installed, so we don’t need to worry about that. Some people prefer servers other than Apache, databases other than MySQL, or languages other than PHP. However, I think these are the easiest to set up and since I spend the majority of my time working with WordPress, this setup suites me well. There is a handly little tool called “tasksel” that will make the installation of the LAMP stack quite painless. We can use the following command to install this tool from the command line:

sudo apt-get install tasksel

Once tasksel is installed, it can be run using the following command:

sudo tasksel

This will bring up a selection dialog within the terminal that will let us easily add additional functionality to our OS. In this case, we want to use the arrow keys to navigate to the LAMP server option and press the space bar to select it.

tasksel screenshot

After this we can hit enter and tasksel will go about installing most of the pieces we need. Part way through the installation process, we will be prompted to create a password for the MySQL root user, but other than the, the process is all automated.

Once this process is finished, visiting¬†http://localhost/ in our browser should display a page titled “It works!”

Just to make things easier, at this point I like to go and change the permissions of the /var/www/ folder (localhost). I set my normal/default user as the owner so that I don’t have to switch users when adding/editing files on the server.

3. Install phpmyadmin

I prefer to use a GUI to mess around with my databases. The following command will install phpmyadmin to hande that:

sudo apt-get install phpmyadmin

This will lead to a few more dialogs. The first will ask which sever we’re using, and we can select apache2. Next we will be asked if we want to configure the dabase for phpmyadmin with dbconfig-common. I have always selected the default value “yes” because I don’t have any reason not to. Next, we will be asked to enter some passwords. I don’t remember the exact wording of the prompts but entering the same password we entered in step 2 will work.

Once this process is complete, phpmyadmin should be accessible by going to http://localhost/phpmyadmin/ in our browser.

4. Install WordPress

I’m not going to explain this step because it is already well documented in the WordPress Codex. However, I’ve added it to the list here because:

  1. Installing WordPress is almost always one of the first things I do.
  2. Having WordPress installed makes it easy to test whether mod_rewrite is working properly, which is covered in the next step.

5. Setup mod_rewrite

The mod_rewrite module is what allows things like “pretty permalinks” in WordPress to work properly. For some reason, getting it working with Ubuntu/Mint is trickier than it should be. In fact, I’ve run into this issue so many times that I’ve already covered it in a different post.

6. Install git

Many of my projects are hosted on GitHub or Bitbucket, so the easiest way to add them to my new machine is with git. This command will install git from the repositories:

sudo apt-get install git

7. Install node.js, npm, and Grunt

I’ve just started using Grunt and I’m impressed at how well it automates tasks and how easily it allows me to make use of more advanced tools such as SASS, JSHint, etc. Node and npm can be installed easily with the following command:

sudo apt-get install npm

Note that only npm is listed, not node. Ubuntu/Mint will automatically calculate the dependencies that are required and install them as well. This includes the nodejs package. This is helpful because there is another package in the repositories simply called “node” which is not the right package and can cause some confusion. Once npm is installed, the Grunt Command Line Interface can be installed with the following command:

sudo npm install -g grunt-cli

This does not install Grunt itself. The grunt-cli package simply adds the grunt command to the system path so that it can be run from any directory. Grunt itself must be installed locally within each project where it is used. For more details on installing Grunt, I would recommend reading this post on installing Grunt by Stephen Harris.

As mentioned earlier, the Node.js package is named nodejs in Ubuntu/Mint. However, some scripts will be looking for “node” rather than “nodejs” so it’s best to create a symlink between the two using the following command:

sudo ln -s /usr/bin/nodejs /usr/bin/node

8. Changing the Apache User

Since by default Apace runs as the user www-data and the /var/www directory now belongs to our default user account, the automatic updates/plugin installs built into WordPress won’t work. To fix this, we just need to adjust Apache to run under our default user account. We can do that by replacing www-data with our default username in the following two lines of the /etc/apache2/envvars file:

export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data

9. Get Back to Work!

So that’s how I set up my local development environment. I left out IDEs/code editors because almost everyone has their own preference and if you have a preference, you probably already know how to install it. I personally use Sublime Text, but like I said, that’s personal preference. I also use VirtualBox to install virtual copies of Windows for testing various browsers, but that’s outside of the scope of this article.

Is there anything else you do to get your local development environment up and running? If so, I’d love to hear about it!

10. Notes

Other things that might be necessary depending on your requirements:

  • PHP GD: A PHP library for working with images.
  • Virtualbox: Virtualization software to enable testing in Windows-only browsers.
  • PublishedMarch 4, 2014
  • Posted InLinux

Creating a Commercial WordPress Theme Review Site in One Week: Day 4

This is the fifth in a series of posts documenting the creation of Theme Friendly, a website dedicated to reviewing commercial WordPress themes.

On day four, I built the search page. This was easily the most difficult part of the entire process. Let’s start with the screenshot.

Day 4 Screenshot


If you read my post covering day 3 you might be thinking, “Hey! this looks almost like the review archive from the last post.” …and you would be right. I reused the template part I created for the review archive to display the search results. Adding the search form was a little more difficult though, and filtering the search results based on the input from the search form was even more difficult. Here’s how it worked… (more…)

  • PublishedJanuary 7, 2014
  • Posted InProjects

Creating a Commercial WordPress Theme Review Site in One Week: Day 3

This is the fourth in a series of posts documenting the creation of Theme Friendly.

On day three, I built the review archives page. I don’t think this page will be used directly, but on day four I incorporated it into the search results page, so it was still worth building.

Day 3 Screenshot


After all the hard work that went into building the single review page on day 2, this page was pretty short and sweet. It only had to display each theme’s title, quality score, thumbnail, and author. Most of the backend code was easily modified from the single review page code. I just had to add a new image size and some CSS to handle the new layout.

In the next post in this series, I’ll be detailing how I built the search functionality that makes it simple to find only themes that match your exact requirements. Sign up for the Theme Friendly newsletter to find out when it is published. Until then, Happy New Year!

  • PublishedDecember 31, 2013
  • Posted InProjects

Creating a Commercial WordPress Theme Review Site in One Week: Day 2

This is the third in a series of posts documenting the creation of Theme Friendly.

On day two, I set about building the individual theme review page. The goal was to provide a quick overview of the quality of a theme as well as it’s features. This was to be done by displaying the contents of all the custom meta boxes and custom taxonomies created on day one.

Day 2 Screenshot



  • PublishedDecember 17, 2013
  • Posted InProjects

Creating a Commercial WordPress Theme Review Site in One Week: Day 0

This is the first in a series of posts documenting the creation of Theme Friendly.

A short history

I’ve been thinking about building a commercial WordPress theme directory for a number of years now. I even tried (and failed) to get one off the ground a few years ago. During that time, a number of other sites sprung up with similar goals and I gradually abandoned my project. However, the idea never left. I kept thinking about what could be done to ease the process of finding the perfect WordPress theme for any particular project. I decided to see if I could build a working solution in just one week.


  • PublishedNovember 27, 2013
  • Posted InProjects

Updating a Plugin in the WordPress.org Repository

As of this writing, I have only two plugins in the WordPress.org repository. I periodically update these plugins, but not often enough to memorize all the steps required to get things right on the first try. So for my own future reference (and maybe yours as well) here are all the steps laid out in order.


« Older Entries