Support

Account

Home Forums General Issues WPAllImport: Select between input values to import to ACF field

Solving

WPAllImport: Select between input values to import to ACF field

  • Hi,
    I have ACF Pro and the pro version of WPAllImport, the excellent content import plugin for WordPress.

    I am importing many users to the WordPress Users table, all in to ACF fields, using WPAllImport’s ACF add-on.

    One of my ACF fields is “avatar_best”, an image field that, with WPAllImport, is intended take an image from a web URL in to the Media Library and to attach that resulting image to the “avatar_best” field.

    Now, the challenge is, the image input URL may come in any one of up to five fields in the source CSV. Those fields are “photo_url”, “cb_avatar”, “cb_twitter_avatar”, “cb_aboutme_avatar”, “cb_gravatar_avatar” – some of these values may be blanks, others filled.

    So, my aims are here…
    1) In WPAllImport, set up some system to step through each of those fields in order and, when the first non-negative value is found, take that URL as the image to be imported to Media Library.
    2) Set the Title of that image in Media Library as another field being imported to an ACF field, “name_full”.
    3) If possible, set the filename of that image in Media Library as another field being imported to an ACF field, “username”.

    I accept that much of this solution may have a little more to do with WPAllImport (which can run custom PHP functions at the time of field import (but which may be over my head), than ACF. But I thought I would ask, given the connection.

    Thanks.

  • First part may be solved with…

    [snip]

    working on it

  • Your best source of information for this is going to be the WP All Import documentation. I would look into creating a custom function that is run for a specific field http://www.wpallimport.com/documentation/advanced/execute-php/… but other than that, I don’t know how you would get what you want. You should contact the support for WPAI, they are usually extremely helpful with this type of thing and they may already have some example code available. Any time I ask them something they generally send me a link to a gist that solves the problem.

  • Indeed. So far, I have this thanks to their help…

    // 4. WPAllImport function - Import "avatar" user meta from first available image URL in input data
    
    function profile_photo($photo_url,$cb_avatar,$cb_twitter_avatar,$cb_aboutme_avatar,$cb_gravatar_avatar){
       if(!empty($photo_url))
           return $photo_url;
       if(!empty($cb_avatar))
           return $cb_avatar;
       if(!empty($cb_twitter_avatar))
           return $cb_twitter_avatar;
       if(!empty($cb_aboutme_avatar))
           return $cb_aboutme_avatar;
       if(!empty($cb_gravatar_avatar))
           return $cb_gravatar_avatar;
    }
    /* Execute in WPAI import using...
    [profile_photo({photo_url[1]}, {cb_avatar[1]}, {cb_twitter_avatar[1]}, {cb_aboutme_avatar[1]}, {cb_gravatar_avatar[1]})]
    ... wherein profile_photo is function name) */

    I will update this thread if I learn more.

    I had looked at the WPAI docs but, though I understand any PHP can be used in the functions and I have a smattering of PHP, I still needed some info to get going on basics like passing variables in and out of the function.

    Thanks.

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

The topic ‘WPAllImport: Select between input values to import to ACF field’ is closed to new replies.