The Advanced Custom Fields plugin is an extremely useful WordPress plugin that allows you to add custom fields to your posts. This is a great way to store extra information about each posts and allows you to have a more bespoke blog.
To install the extension, either upload the .tgz file you downloaded from your account on FishPig.co.uk to Magento via the Direct Package File Uploader in your Magento Downloader and refresh the cache or extract the .tgz file and merge the files via FTP with your Magento root directory. If you choose to merge the files, you can ignore the package.xml.
For this extension to work, you will also need the Advanced Custom Fields plugin installed in WordPress.
Once you have setup your fields in the WordPress Admin and populated some posts with data, you're probably wondering how to actually access that data in your Magento templates. Fortunately, this is the easy part!
WordPress Integration provides a method on the Post model named getMetaValue(string metaKey). By default this method searches the post meta table in WordPress for a value that has a meta key matching the first parameter of the method. The ACF extension uses an event to alter this method so that if an ACF field exists for the post with this key, this value is returned.
Get an ACF Value for a Post
Here is an example of how to get a ACF field that has a field name of 'my_acf_field'.
<?php $acfValue = $post->getMetaValue('my_acf_field') ?>
This works for all field types available in ACF, including the repeater field. When a repeater field is used, the above method returns an array containing all rows and fields inside each row.
Get an ACF Options Value
The ACF extension now supports the custom options feature of Advanced Custom FIelds. This allows you to specify ACF fields that aren't associated with any particular post, but instead, are global to the blog. These values are like static blocks in Magento, except easy to use and actually useful!
The below code demonstrates how to get an ACF option with a field name of my_acf_option.
<?php $acfOptionsValue = Mage::helper('wp_acf')->getOptionValue('my_acf_option') ?>
If you're having problems with this extension, the first to do is check that you are using the latest version. When upgrading this extension, always upgrade WordPress Integration at the same time, as all development testing is carried out using the latest versions of both extensions.
If your problem persists after upgrading, you get in touch via our contact form and we'll do our best to help you.
Have Your Say...
If you have used WordPress Advanced Custom Fields Integration and want to share your opinion, you can leave a review by clicking here.
- LJ ScottI've been bugging Ben about creating this extension for a while and over the moon that he has finally completed it (sorry for all the pestering but am leaving the review as promised!!)
It works great and allows me to increase the complexity of my blog so it is no longer a standard text list style blog. I now have advanced custom data that my blog copywriters can assign to each post and my templates pick this up and display it perfectly.
Who should get this?
If you happen to be using a lot of custom fields in your articles and are tired of having to recreate them each time, advanced custom fields allows you to create groups of custom fields and assign them to posts based on rules. Each time you go to a post in the Wordpress Admin these fields are already listed for you to just enter the content in directly.
Also recommend this extension for people wanting more than simply custom fields and want to include images, post relationships, dates and other complex types