Domain mapping with WordPress multisite without using IP addresses

I am currently the lead back-end developer over at Highrise Digital, in charge of a large (over 500 sites) multisite installation of WordPress. Each site in the install has its own custom mapped domain, rather than using a subdomain of the primary site. In this post, I discuss how I set up domain mapping to websites in the WordPress multisite install, without pointing the domains to the servers IP address.

Continue reading Domain mapping with WordPress multisite without using IP addresses

Changes to Registering Custom Post Types in WordPress 4.4

Whilst building a plugin recently I found a change in WordPress 4.4 which actually broke my plugin, but was very easy to fix. The problem was with a custom post type that had completely disappeared from the admin menu. Here is why it disappeared and how I got it back again!

First a little background about the plugin in question. It used a post type in order for the user to add a single post. The content of this single post was then outputted with a shortcode and therefore I did not want the post type to have a permalink page at all. For this I had set the public argument used in register_post_type() to false. I also did not want the regular post type menu item to show in the backend, as I was adding my own menu item and therefore I had set the show_ui argument to false too. This worked fine in WordPress 4.3.1 and when I added my own menu item using add_menu_page() which used the edit post screen for the content for a post within the custom post type the menu item showed up no problem.

When I recently upgraded the site to WordPress 4.4 there was a large problem. The menu item completed disappeared. After some digging around and making some changes to test what was going on, I found the problem. The fix was to set show_ui to false but to set show_in_menu to true.

When I tweeted about this issue, John Blackbourn, one of the core developers kindly responded with a link to a post outlining the changes.

WP Skeleton – A Starter Repository for Building WordPress Sites

Being a WordPress developer I build a lot of sites and getting things started can take a lot of time. Getting your site, themes plugins etc. ready to go, seems to always take longer than it should, as well as being something that we keep repeating. I therefore went about solving this in a fairly low level simplified way. What I created, I am calling WP Skeleton.

View WP Skeleton Code Repository on Github

Continue reading WP Skeleton – A Starter Repository for Building WordPress Sites

AJAX WordPress Search

You know when you type a search in Google and then it always shows some suggestions below, well recently I had a client who wanted something very similar using their WordPress site. This posts looks at how I implemented a similar feature to a site to show any posts as suggestions, which met the search criteria.

The site in question was a recruitment site and one that I was tasked with integrating my ever increasingly popular WP Broadbean plugin with. Therefore the site had lots of job posts, which are a custom post type and the clients requirements were that the user should be able to search for a job by title (and other parameters which are not relevant here so I won’t go into those details).

Continue reading AJAX WordPress Search

Broadbean Integration with WP Job Manager

For past couple of years I have worked on a plugin called WP Broadbean. This plugin integrates Broadbean‘s job Adcourier posting service with your WordPress site, allowing jobs posting through Broadbean to delivered to your site. While this plugin is working well, I have had multiple enquiries about integrating Broadbean job posting with the popular WP Job Manager plugin. Well today I am announcing that I can now offer this integration too. Let me explain a little more.

The WP Job Manager plugin is a plugin to provide Job board functionality to your WordPress site and was developed by Mike Jolly who works on the WooCommerce project. The plugin is very good and provides a jobs post type and associated taxonomies and meta fields for jobs, similar to the WP Broadbean plugin. It also has a nice AJAX style search built in to allow candidates to search for jobs in specific categories etc. as well as allowing candidates to apply for a job through the site.

These are mainly the features that the WP Broadbean plugin has. Although using my stand-alone plugin is more specific to Broadbean job posting itself, I can see the advantages of using the WP Job Manager plugin with its community and increased usage.

So onto my integration then. I have a built a WordPress plugin which acts as an addon for the WP Job Manager plugin. This provides an additional settings screen where site owners can create a username and password in order to setup their feed with Broadbean.

The plugin works even with sites that have registered additional fields in the WP Job Manager plugin so that it picks these up without any additional development, assuming of course they have been added correctly using the hooks and filters provided by WP Job Manager.

It also hooks into the application form to allow candidate applications made on the WordPress site to be tracked in from within Broadbean along with applications for other sources or job boards.

If you are interested in integrating Broadbean with the WordPress and the WP Job Manager plugin then please do get in touch for a quote.

Using the Media Handle Sideload Function

WordPress is equipped with lots of great functions that you probably haven’t heard of and recently I came across a couple of little gems whilst working on a project. He is how I used the media_handle_sideload function in a project.

The project in question was an integration of Broadbean with the WP Job Manager WordPress plugin. In fact the work I have done will soon to be a service offered on their add-ons page along with the LogicMelon add-on service I already have on there.

I needed to be able to take a URL which was being sent to the WordPress site which was a PDF, Word document or an image and have WordPress add this file to the media library so that I could link to it on the WordPress site.

Having done some investigation I came across the media_handle_sideload function which effectively does just that. It will take a URL, and attach it to a post.

Below is the code I have used to grab a file from a URL and attach it to a post. It is well commented in order to help understand what is going on!

It is a really handy function and one I am sure I will use more with plugins and code that require that or a similar functionality.

WP Broadbean Plugin Updates

In early 2014 I launched the first beta version of the WP Broadbean WordPress plugin. This is a plugin to integrate Broadbean Adcourier job postings with a WordPress website. The plugin has evolved and changed since then and therefore lets take a look at some of the plugins features.

Lets outline some of the new features of the plugin which have been introduced after the initial launch:

Extensibility

The plugin has been made as extensible as possible from the start. However as development has progressed it has become more obvious that additional extensible features could be utilised. Many of these have come from developers in the community using the plugin and feeding back to me.

There are now a number of hooks and filters that allow developers to extend upon and alter the functionality of the plugin. For example developers can use a different inbox.php file which processes each job simply by using a template override. Developers can also use filters to add additional job fields and taxonomies to the job postings should they wish to.

It is worth remembering however the more customisations made with the plugin through its extensible features, the more changes Broadbean will need to make to the feed which is used to send jobs to your site.

Below are some of the new filters you can use:

  • wpbb_query_var_value – allows you to change the URL query var to which jobs are posted to. This defaults to broadbean but developers could change this to something else.
  • wpbb_application_form_html – using this filter would allow developers to alter the markup of the application form used to allow candidates to apply for jobs
  • wpbb_application_allowed_file_types – a filter that allows editing of the file types that are allowed by default in the CV upload field on the application form
  • wpbb_apply_url – with this filter you can amend the URL used for applying for jobs. This means you could change the URL completely, maybe to use your own form or you could perhaps add additional query variables to the URL which you may use in your application form.
  • wpbb_admin_sub_menus – allows developers to add a sub menu beneath the main WP Broadbean menu
  • wpbb_registered_settings – add additional settings to the WP Broadbean settings admin page

There are many new action hooks you can utilise too:

  • wpbb_job_term_added – a hook that fires after a term has been added to a job when sent through from Broadbean
  • wpbb_job_field_added – this hooks fires after a field is added (post meta) to a job when sent through from Broadbean
  • wpbb_job_added – after the job is added along with all the fields and the terms this hook is fired. Can be good for actioning things like clearing search caches etc. which need to be re-built when a new job or post is added.

There are many more and I would encourage you to search the code-base for apply_filters and do_action.

Application Form

The application form has changed along the way to, for the better I think. It now no longer uses a shortcode but instead you select which is your apply page in the WP Broadbean settings page. The application form is then appended to any page content you may have on that page.

The form also now includes a field for a message, something which many users requested.

Finally the form now also allows the upload of Word and Pages documents as well as the original PDF document type. Even these can be changed with a filter.

Attachments to Email Notifications

One of the initial issues with the plugin which was reported to me was that the application form was not emailing Broadbean correctly or not attaching the applicants CV to the email. This is something that is important for the tracking of an application from within the Adcourier system.

These issues have now been fixed and all the emails that are sent through to Broadbean will have the applicants CV attached.

Those are the main changes and alterations to the plugin which I hope make it much better for users and developers to take advantage of. Do remember that I offer a Broadbean Assist service where I can integrate Broadbean with your WordPress site for just £599 which takes the hassle out of doing it yourself.

Over the coming months I have some additional plans for the Broadbean plugin with a view to integrating this into some other services – watch this space. Oh and don’t forget that I recently launched a plugin for integrating WordPress with LogicMelon over at wplogicmelon.com – you can read a little more about this here!

Sort Posts by Term on Custom Post Type Archives

When building sites with WordPress I often make use of custom post types to add custom content types. I also use the custom post type archives in order to display an archive of this content. Recently I came across an issue where I wanted to be able to list posts on the archive grouped by terms from a taxonomy. Having quickly found out this was not so easy, I set about trying to find a solution.

The client site I was working on wanted to have a meet the team page. In fact this is a popular request amongst clients and something I often have to do. Therefore to achieve this I use a custom post type called person (prefixed of course). For the purpose of this post the custom post type is called wpmark_person.

This particular project was very specific in that it needed to have the people in the team split into the different sections they belonged to in the company e.g. Senior Leaders, Teachers etc. To achieve this grouping of posts I used a custom taxonomy which was named wpmark_person_type.

Now came the issue of displaying the team members. The design called for a page which was split into different sections, each section being a type of person (the different person types from my taxonomy). The people belonging to that section where then listed under those headings (as a thumbnail images) and each section was collapsed by default (I used jQuery to expand/contract the section but that is not covered here). Clicking the person type title revealed the actual people, in this case an image linking through to the person single post view.

Below is a wireframe of what the page layout for the meet the team would look like.

The wireframe provided indicated a different sorting of posts.
The wireframe provided indicated a different sorting of posts.

With custom post types you can declare an argument when register the custom post type of whether or not you want it to have an archive. This archive, like posts (your sites blog in a vanilla WordPress install) lists the posts in chronological order with the newest first, paginated according the number of posts per page set in the WordPress settings area for reading.

Essentially this was what I wanted, however I just wanted to order them differently and show them all. Instead of ordering them by date, I wanted to have them ordered by term from the person type taxonomy. Therefore all posts from one term and then all posts from the next etc.

In essence this is straight forward to do, but would require you to add lots of custom loops to the archive using WP_Query. This was something that I didn’t really want to do as it would mean that I am querying things twice. WordPress would query the person posts (as normal for the post type archive) and then I would throw this query away and get the posts again within the different terms. As I already have the posts I want and it was just a matter of re-ordering them, I decided there must be a more efficient way and went about tying to find a solution. First I posted on the WordPress.org support forums after¬†Google searches revealed little.

I posted on the WordPress Support Forums for a Solution
I posted on the WordPress Support Forums for a Solution

After much trial and error and testing I landed on a solution that worked. Using the Query Monitor plugin I could see that it only added one more query to the page, which I thought was reasonable. My solution is as follows.

The first part was to make the archive show all the posts for that post type. I did not want pagination here and therefore wanted every person to be listed, albeit in their respective person types. To do this I used the excellent pre_get_posts action which allows you to change the query parameters WordPress uses before it actually queries the database for posts. Below shows the code to do this:

So now I have a post type archive that queries all the person posts. I can access these by the normal loop, however I needed to do some ordering before that. Therefore I need to get the post objects for these posts and manipulate them. I can access my posts through $wp_query->posts which is what I needed.

The next part was to create a function that would output an array of all the posts, split into the different terms they were assigned to. Essentially the output of my function would be like so:

The function that I used to do this was like so:

Lets talk through what this is doing. First we set some default args, which can of course be changed if passed through to the function as an array of parameters. We then create an empty output array to fill with all the terms and posts.

The first real part in the function is to get all the terms from the taxonomy (in this case are person type taxonomy). This is actually the one additional query that is carried out on the page. When we do this we are going to order them by their ID. The one created first, is shown first although we could order by name etc. We are also going to just return the term names here to keep the query as light as possible as the name is all we need to output on the page.

We then loop through each term, adding the term name as a key to our output array. Next we loop through all the posts (remember these were queried in the normal process of using a post type archive and we passed them to this function using $wp_query->posts). Inside this loop we get all the terms this post has (it should only be one as the UI for this taxonomy only enable one term to be assigned) and then push this post object into an array inside our output array for this term. Finally we return the entire array, which is now sorted into terms and posts.

Back on the post type archive template now we can use this code to output the posts.

Summarising the above code, we loop through the top level elements of the array first outputing the term name as a title. We then do a second loop through to output the posts within that term.

The output of the page looks lie this:

Custom Post Types Archive with Posted Ordered By Term
Custom Post Types Archive with Posted Ordered By Term

So there you have it, if you ever want to sort posts by a specific taxonomy term of a post type archive you can do it with just one additional query.

Introducing WP LogicMelon

Back in late 2013 I started work on a plugin to integrate Broadbean with WordPress. This allows [mainly] recruiters to post jobs more easily from Broadbean to their WordPress site. Another solution for recruiters is LogicMelon, a similar solution to posting jobs to multiple platforms. After a few client requests for a solution which would work similar to WP Broadbean I have built WP LogicMelon, a WordPress plugin to integrate LogicMelon with WordPress.

Job Listing with WP LogicMelon
Jobs are saved as a custom post type with associated taxonomies and meta data.

The LogicMelon software allows recruiters to post jobs once using their software and then the posted job appears on many of the major platforms and jobs sites. As part of this posting, LogicMelon can send the job to your own website.

Obviously when this happens your site needs to accept the data sent, process it and then output it on the front end of your site to allow your candidates to view the information.

The WP LogicMelon plugin solution provides all this functionality. It accepts an XML feed sent (and built) by LogicMelon and saves this data as a custom post type with associated meta data and taxonomies.

The plugin is broadly based on the WP Broadbean Plugin solution with one or two tweaks to make it work for LogicMelon.

To find out more about getting your WordPress site integrated with LogicMelon, head on over to the WP LogicMelon website in order to find out more.