Make your wordpress development easier with Advanced Custom Fields Plugin

WordPress is getting undeniable day by day. Its getting powerful, lots of new features are added up.  Easy customization and flexibility are the highlights of wordpress.

WordPress meta fields are one of the best features of wordpress. It makes your developments very easy. Its very flexible too.

What is  the use of wordpress meta fields?

I am briefly explaining wordpress meta fields for peoples who doesn’t know much about it, I’ll explain it with a simple scenario. Just Imagine that you are having a real estate website in wordpress. You have created a custom post type properties for the listings.

  • What if you need a special column for price in the wordpress properties post type admin?
  • What if you want to save the price in  a special row in database?
  • What if you want to display the price alone in the Properties  view page?

WordPress meta fields make this possible, there are two major functions in wordpress.

1. add_post_meta

add_post_meta($post_id, $meta_key, $meta_value);

Meta field is connected to the post id in the database table. A specific meta key and its value is set for a specific post in wordpress (with respect to the post id)

In our case regarding the property and price.

$meta_key will be “price” and $meta_value will be the amount say 500.  This will be saved in the database.

2. get_post_meta

$meta_values = get_post_meta( $post_id, $key);

We can retrieve the set meta values using get_post_meta. In our example we can retrieve the meta key price and its meta value so that we can display it in the property listing or view page. Different price will be given for different  properties(post id).

Advantages of Advanced custom fields.

So how does Advanced custom fields help us? It helps us implementing the meta fields easily. Advanced custom fields  plugin will create the required meta fields (text field, drop down,select or other html form fields) in our wordpress post admin so that we doesn’t need to call the wordpress add_meta_box function(it creates a meta box inside the wordpress post admin, and we should to create the input text fields and all inside it ). Here is were ACF saves our time.

The custom fields can be set for posts,pages,post types in the Advanced Custom Fields plugin settings and it will be shown up inside the post or page admin. The values saved can be retrieved using the get_post_meta function. Have a look at the below screen shots which shows the implementation of ACF plugin.

1. Advanced Custom Fields Settings (Creating Fields in admin)

advanced custom fields - settings

2. Advanced Custom Fields Rules ( Defining where should we set the custom fields(posts,pages etc).

advanced custom fields - rules

3. How Advanced Custom Fields  is displayed in the post/page admin?

advanced custom fields - post admin

Download Advanced Custom Fields Plugin

About the author

Linjo Joson

Linjo is a PHP developer who loves to write about online businesses and marketing ideas

Add comment

Categories