Support

Account

Home Forums General Issues Need help with fields, developer question.

Solving

Need help with fields, developer question.

  • How to either import posts with the custom fields? Or how to get all fields of a field group?

  • Hi,

    How to either import posts with the custom fields?
    ACF uses a post type and custom field metadata to save all the custom field objects.

    This means you can use the export feature in ACF to obtain a .xml file which you can import into a WP install via the default WP import tool!

    Or how to get all fields of a field group?
    Are you asking how via code?

  • Yes via code. I’m using a plugin from another vendor that needs to be updated.

    Zach

  • What is the default format i can use for the WP import?

  • WP has an export / import tool built in. You can access this via Tools -> Import

    You can export ACF to this .xml format via Custom Fields->Export.

    You will also find instructions on that page

  • I checked out the dump from the custom fields export. It looks like it stores all the data from the actual value as a PHP serialization. This creates a problem for what I’m trying to do. I need to bulk import from a csv a custom post type that has custom fields. I’m using your custom fields plugin for the fields. I have plugin that used to import fields with your plugin. It seems like the code has been deprecated since then.

    In PHP, how would I get all the fields of a field group along with the rules? Your documentation is very clear on how to do that.

  • I think I have miss0understood your original question due to the language barrier.

    Are you asking how to export / import custom field objects?
    Or are you asking hoe to export / import custom field values?

  • Values.

    I have a spreadsheet with posts and additional fields (custom fields). I want to import this into WP. Not seeing how to do that.

    Zach

  • i was able to figure it out. For anyone else wondering…

    
    // To get field groups:
    $fieldgroups = apply_filters('acf/get_field_groups');
    
    // To get rules: 
    $location = apply_filters('acf/field_group/get_location', [], $fieldgroup['id']);
    
    // To get fields of group:
    $groupFields = apply_filters('acf/field_group/get_fields', [], $fieldgroup['id']);
    
  • Btw square brackets are the new in php5.4 for short notation of array(). If you are using <5.4 then use array().

  • @zquintana,
    Nice workaround and thanks for the info on brackets (seems like PHP is borrowing a thing or two from javascript)

  • Hi @zquintana

    Great work on the code. Would you mind editing that reply and marking it as the topic solution?

    Thanks mate

  • Anyone that stumbles across this post in need of help with importing a CSV of posts into WP, try out this plugin. It allows you to add columns for all of the default WP fields like the_title, the_content and so on. It also allows any custom fields to be added as columns, so ACF is completely compatible.

    In fact, you can even stick a repeater field into the CSV. I done this for a recent site.

    You’d have the columns like:
    repeater_0_text, repeater_1_text, repeater_2_text, repeater_3_text

    And then another just called ‘repeater’, with the amount of sub-fields (in this example, the value would be 4).

    Give it a try! Hope this helps someone one day.

    http://wordpress.org/plugins/csv-importer/screenshots/ (I know it’s old, but it works)

  • Also as rmdev stated above, if anyone stumbles across this particular post I too import ALOT of data to my various sites, BUT I use WP Ultimate CSV Importer simply because it maps well to the fields of the DB including the custom fields from ACF. No need for urlencode and I’m normally importing 1000’s of records for my updates, no problems.
    http://wordpress.org/plugins/wp-ultimate-csv-importer/

    I also use Navicat because I can map to specific fields, but ONLY when I can deal with field(s) that I’m only updating data that is already there! Keywords are “data that is already there” as in update/append the field.

  • Are you using the pro version of WP Ultimate?

  • Not just yet, I was waiting for them to do their major update that would work with ‘custom’ posts. I was using the free edition. But now, with this next project I will be getting pro.

  • Whew! I just tried it and it mostly worked.

    I ran into a funny bug where field that alphabetically fall lower than “f” don’t map. So I had to rename my fields to bump them higher alphabetically (first_name became “a_first_name” and so on). Once I did that, it worked.

    I really appreciate the tip. I was scared that I was going to have to build out 500+ employees manually. So I’m thrilled that this will take care of the bulk of the data.

    Thanks!

Viewing 18 posts - 1 through 18 (of 18 total)

The topic ‘Need help with fields, developer question.’ is closed to new replies.