Bobcares

ACF Import JSON programmatically: How to?

by | Apr 18, 2023

Let us go through a step by step guide on how to import ACF JSON programmatically. Our WordPress support services at Bobcares will answer all of your questions and doubts on wordpress plugins.

What is ACF?

ACF (Advanced Custom Fields) is a WordPress plugin that allows users to add custom fields to their posts, pages, and custom post types. ACF allows a user to import and export custom field settings in JSON format.

This function is important if we need to relocate their custom fields from one website to another or back up their custom fields settings.

How to import ACF JSON programmatically?

Follow the steps given below to do this:

  1. Firstly fucn the user has to create a JSON file containt the ACF Settings:

    The first step is to generate a JSON file with the ACF configuration. This is accomplished by navigating to the ACF plugin settings page in the WordPress admin and selecting the “Export” option.

    We then choose which field groups to export and obtain a JSON file with the settings.

    Alternatively, we may use a text editor or an online JSON editor to manually construct a JSON file with the ACF parameters. The JSON file should be in the same format as the ACF file.

  2. After that upload the JSON file in to the WordPress site:

    We need to upload the JSON file to the WordPress site once we get it. We achieved this by uploading the file to the WordPress installation directory using an FTP client or by uploading the file to the media library with the WordPress media uploader.

  3. Finally, use the acf/import_field_group_from_json fucntion. This will import the ACF settings.

    After uploading the JSON file to the WordPress site, we will use the:

    acf/import_field_group_from_json

    method to programmatically import the ACF settings.

Example code for importing an ACF JSON file programmatically

Code snippet explanation

Let’s take this code sample step by step:

  1. First, we specify the location of the JSON file containing our ACF settings. 'path/to/your/json/file.json': W ehave to replace this with the actual path to the JSON file.
  2. The contents of the JSON file are then obtained using the file_get_contents method and stored in the $json_data variable.
  3. The JSON data is then decoded into an array and stored in the $field_group variable using the json_decode function.
  4. Finally, we import the ACF field group using the acf_import_field_group method.

    The function accepts an array of $field_groups as an input and returns a boolean result indicating whether or not the import was successful.

    Depending on the outcome of the import, the $result variable will contain either true or false. For this code to operate, the ACF plugin must be installed and enabled on the WordPress site.

[Need assistance with similar queries? We are here to help]

Conclusion

To sum up, our support techs have now shown us how to import ACF JSON programmatically in WordPress.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

2 Comments

  1. leah

    Is it now possible to see and edit the fields in the site administration?

    Reply
    • Hiba Razak

      Yes. Programmatically imported ACF fields are visible and editable in the standard ACF admin area after import.

      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF