Advanced Custom Fields & Admin Custom Columns

In this tutorial, we will add 2 extra fields to the page object:

  • Page Image: An image field (we can show this as a thumbnail in the column)
  • Featured: A true / false field (we can filter the pages via this field)

 1. Add extra page fields

Using the Advanced Custom Fields Plugin, add a new ACF group with the 2 fields. Note: The image field needs to save the attachment ID so we can easily retrieve the thumbnail version for the column.

2. Add a sprinkle of code

Now that our pages have extra fields, let’s add in the code to show the fields in the page’s columns. The 2 functions bellow hook into WordPress and override the column creation process. the “my_page_columns” function overrides what the columns are and the “my_custom_columns” function tells WordPress what to do with the columns.

This is what your page columns should look like

 3. And a pinch of salt: Sortable Columns

To finish of this tutorial, lets now allow the featured column to be sortable. This can be a very useful feature when working with lots of page / post objects.

Wrapping Up

I hope you enjoyed this simple but useful tutorial. We covered some advanced WordPress & PHP techniques and created an attractive and user friendly admin edit page. Be sure to tweet about this article, thanks for reading.

 

Elliot Condon is a Melbourne based web developer, creator of the popular Advanced Custom Fields WordPress plugin and many other websites and web-apps.

Elliot Condon is a Melbourne based web developer, creator of the popular Advanced Custom Fields WordPress plugin and many other websites and web-apps.

Thank you for reading

Join in the discussion bellow by tweeting about this post. 15 comments

Thanks again

Join in the discussion by tweeting about this post.