Skip to main content
We are Brand SEO Beijing serving international business, your marketing partner, Contact us by mi@mgsh.com.cn

Custom Fields Plugin: Advanced Custom Fields

Advanced Custom Fields is a very powerful custom field plugin that allows you to add various forms of custom field types, such as Image, Checkbox, File, Text, Select, True/False, Link, Textarea, etc. Become one or more panels, support exporting fields as xml or php code, and can also be integrated into themes or plugins.You can use this WORDPRESS plugin to create custom fields for pages, articles, categories, users.You can use this plugin to create a page field for website settings, which can be used to freely edit the website's title, LOGO, banner, copyright text, etc. as long as you want.For example, a screenshot of a page I once created:
2017 05 27100-brand-SEO-public opinion-optimization-米国生活
Below I will introduce a detailed method of using this plugin:

Install plugin

1. Search Advanced Custom Fields in the background plugin installation interface to install it online
2. After enabling the plugin, you can see "Field" in the left menu, click "New" after entering, and an interface similar to the following will appear.
2017 05 278-brand-SEO-public opinion-optimization-米国生活

How to use it

add field

As shown in the figure above, click the blue Add Field button, and an entry for adding a field will pop up for you, as shown in the following figure:
2017 05 2726-brand-SEO-public opinion-optimization-米国生活
Key explanation:
The choice of field type is very useful. For example, you can create a field with a lot of filling content through a text segment or a visual editor, you can also create a field for uploading an image with an image, or you can create a field for uploading an attachment with a file. field.
2017 05 2785-brand-SEO-public opinion-optimization-米国生活

Set where the field is displayed

The location options are shown below. You can test the specific ones yourself, so I won't introduce them further.
2017 05 278 1-Brand-SEO-Public Opinion-Optimization-米国生活
It is worth noting that if you want to add multiple rules, such as "About Us" and "Contact Us" display fields on the page, then click the Add Rule Group in the figure below to add a new one.
2017 05 2718-brand-SEO-public opinion-optimization-米国生活

Get the field content in the foreground

You need to use the front desk to get the content of the corresponding custom field.

<?php the_field($field_name, $post_id); ?>

$ field_name: The name of the field to be retrieved (that is, the one with the English name above).For example "page_content" (required)
$post_id: The specific post ID for the input value.Defaults to the current post IDNot required (for example, it does not need to be filled in the looping article and article page).This can also be options/categories/users etc.
Value displayed elsewhere

$post_id = null; // current post
$post_id = 1; // post 1
$post_id = "option"; // options page
$post_id = "options"; // same as above
$post_id = "category_2"; // target a specific category
$post_id = "event_3"; // target a specific taxonomy (this tax is called "event")
$post_id = "user_1"; // target a specific user (user id = 1)
the_field( "text_field", $post_id );

For example, if you want to get the field "_fengmiantu" you created in the category ID 1, then you can write:

<?php the_field(‘_fengmiantu’, 'category_1'); ?>

If you are on the category list page, you can use the method of obtaining ID to automatically obtain the fields corresponding to different categories, which can be written like this;

 
 

If you want to get the image field, when you first create the field, select the image URL, as shown below:
2017 05 2731-brand-SEO-public opinion-optimization-米国生活
Then the front desk uses the following method to get the picture:

<img src="<?php the_field($field_name, $post_id); ?>">

How custom post types use fields

1. The method of customizing the article type category page to obtain the category custom field:

taxonomy; $term_id = $queried_object->term_id; ?> /**Use the following code where you need to get fields**/ /** Just change _fmt to your field name**/

2. Customize the article type article page to get the fields of the custom category

ID, 'product_category', array("fields" => "all"));/**product_category is the name of your custom taxonomy**/ $term_id = $term_list[0]->term_taxonomy_id ; ?> /* *Use the code below where you need to get the fields**/ /** Only need to modify _fmt to your field name (product_category is the name of your custom taxonomy, replace and modify according to your situation)**/
Back to Top