Forum Replies Created

Viewing 15 replies - 16 through 30 (of 66 total)
  • Thread Starter dalemoore

    (@dalemoore)

    I’m not sure what the deal is, but we just switched to using ® and ™ and they import fine. Using the actual characters produces the diamond with question mark and cuts off the rest of the title that follows it. I tried saving the CSV both with Excel as “Windows Comma Separated Values”, and exporting as CSV from Apple Numbers using UTF-8. It may be something in one of the filters.

    Thread Starter dalemoore

    (@dalemoore)

    So that means that it will return boolean false regardless?

    Anyway, thanks for that correction! Seems to work perfectly now.

    Thread Starter dalemoore

    (@dalemoore)

    Success!

    I got one of my programmer co-workers to step in and help me arrange the PHP array properly. Also, stupidly, I was naming the meta_array wrong – it should have been (cfs_)plant_rating, not (cfs_)plant_ratings, which is why it wasn’t saving. -_- (I had originally called it plant_ratings when I was using Advanced Custom Fields, but I switched to Custom Field Suite, and got rid of the s, but forgot)

    Here is the final code:

    function rsci_meta_filter( $meta, $post, $is_update ) {
    
      // Arrays to store data
      $meta_array = array();
      $plant_ratings = array();
    
      // Separate the fields at the comma
      $values = explode(',', $meta['cfs_plant_rating_values']); // imports the comma-separated ratings
      $dates = explode(',', $meta['cfs_plant_rating_dates']); // imports the comma-separated dates
    
      $c = 0;
      foreach ($dates as $key => $val){
      	$tmp = array();
      	$tmp['plant_rating_values'] = $values[$c];
      	$tmp['plant_rating_dates'] = $dates[$c];
      	$plant_ratings[] = $tmp;
      	$c++;
      }
    
      // Insert repeater data
      $meta_array['cfs_plant_rating'] = $plant_ratings;
      return $meta_array;
    }
    add_filter( 'really_simple_csv_importer_save_meta', 'rsci_meta_filter', 10, 3 );

    Thread Starter dalemoore

    (@dalemoore)

    Think I’m closer!

    function rsci_meta_filter( $meta, $post, $is_update ) {
    
        $meta_array = array();
        $plant_ratings = array();
    
        $values = explode(',', $meta['cfs_plant_rating_values']);
        $dates = explode(',', $meta['cfs_plant_rating_dates']);
    
        $ratings_data = array_combine($dates, $values);
    
        foreach ($ratings_data as $ratings_key => $ratings_value) {
            $plant_ratings['plant_rating_dates'][] = $ratings_key;
            $plant_ratings['plant_rating_values'][] = $ratings_value;
        }
    
        $meta_array['plant_ratings'] = $plant_ratings;
    
        return $meta_array;
    
    }
    add_filter( 'really_simple_csv_importer_save_meta', 'rsci_meta_filter', 10, 3 );

    This seems to work in the debugger, but when I disable the debugger plugin and run it, nothing gets saved to the posts. It doesn’t do the “Import CSV 1.” thing though.

    This is what appears in the debugger:

    $is_update:
    bool(true)
    $post:
    array(8) {
      ["post_type"]=>
      string(5) "plant"
      ["ID"]=>
      string(2) "68"
      ["post_name"]=>
      string(27) "lobularia-blushing-princess"
      ["post_author"]=>
      int(41)
      ["post_date"]=>
      string(19) "2015-01-12 19:48:00"
      ["post_status"]=>
      string(7) "publish"
      ["post_title"]=>
      string(29) "Lobularia 'Blushing Princess'"
      ["post_content"]=>
      string(139) "Sprayed 3 times to control spider mite damage.
    
    This is a test on Lobularia. Does it update from the spreadsheet?
    
    Fertilized once a month."
    }
    $meta:
    array(1) {
      ["plant_ratings"]=>
      array(2) {
        ["plant_rating_dates"]=>
        array(2) {
          [0]=>
          string(10) "2014-04-12"
          [1]=>
          string(10) "2014-06-12"
        }
        ["plant_rating_values"]=>
        array(2) {
          [0]=>
          string(3) "3.5"
          [1]=>
          string(1) "5"
        }
      }
    }
    $tax:
    array(1) {
      ["company"]=>
      array(1) {
        [0]=>
        string(14) "Proven Winners"
      }
    }
    $is_update:
    bool(true)
    $post:
    array(8) {
      ["post_type"]=>
      string(5) "plant"
      ["ID"]=>
      string(2) "71"
      ["post_name"]=>
      string(8) "marigold"
      ["post_author"]=>
      int(41)
      ["post_date"]=>
      string(19) "2015-01-20 20:02:00"
      ["post_status"]=>
      string(7) "publish"
      ["post_title"]=>
      string(8) "Marigold"
      ["post_content"]=>
      string(74) "Sprayed 3 times to control spider mite damage.
    
    Fertilized once a month."
    }
    $meta:
    array(1) {
      ["plant_ratings"]=>
      array(2) {
        ["plant_rating_dates"]=>
        array(2) {
          [0]=>
          string(10) "2014-12-24"
          [1]=>
          string(10) "2014-12-29"
        }
        ["plant_rating_values"]=>
        array(2) {
          [0]=>
          string(1) "4"
          [1]=>
          string(3) "3.5"
        }
      }
    }
    $tax:
    array(1) {
      ["company"]=>
      array(1) {
        [0]=>
        string(4) "Ball"
      }
    }
    $is_update:
    bool(true)
    $post:
    array(8) {
      ["post_type"]=>
      string(5) "plant"
      ["ID"]=>
      string(2) "73"
      ["post_name"]=>
      string(5) "vinca"
      ["post_author"]=>
      int(41)
      ["post_date"]=>
      string(19) "2015-01-20 20:13:00"
      ["post_status"]=>
      string(7) "publish"
      ["post_title"]=>
      string(5) "Vinca"
      ["post_content"]=>
      string(74) "Sprayed 3 times to control spider mite damage.
    
    Fertilized once a month."
    }
    $meta:
    array(1) {
      ["plant_ratings"]=>
      array(2) {
        ["plant_rating_dates"]=>
        array(2) {
          [0]=>
          string(10) "2014-03-12"
          [1]=>
          string(10) "2014-05-11"
        }
        ["plant_rating_values"]=>
        array(2) {
          [0]=>
          string(1) "4"
          [1]=>
          string(3) "3.5"
        }
      }
    }
    $tax:
    array(1) {
      ["company"]=>
      array(1) {
        [0]=>
        string(6) "Sakata"
      }
    }
    $is_update:
    bool(true)
    $post:
    array(8) {
      ["post_type"]=>
      string(5) "plant"
      ["ID"]=>
      string(2) "75"
      ["post_name"]=>
      string(7) "petunia"
      ["post_author"]=>
      int(41)
      ["post_date"]=>
      string(19) "2015-01-21 20:13:00"
      ["post_status"]=>
      string(7) "publish"
      ["post_title"]=>
      string(7) "Petunia"
      ["post_content"]=>
      string(90) "Sprayed 3 times to control spider mite damage.
    
    This is Petunia.
    
    Fertilized once a month."
    }
    $meta:
    array(1) {
      ["plant_ratings"]=>
      array(2) {
        ["plant_rating_dates"]=>
        array(5) {
          [0]=>
          string(10) "2014-12-05"
          [1]=>
          string(10) "2015-01-04"
          [2]=>
          string(10) "2015-01-10"
          [3]=>
          string(10) "2015-01-20"
          [4]=>
          string(10) "2015-02-12"
        }
        ["plant_rating_values"]=>
        array(5) {
          [0]=>
          string(1) "4"
          [1]=>
          string(3) "3.5"
          [2]=>
          string(1) "2"
          [3]=>
          string(1) "4"
          [4]=>
          string(1) "5"
        }
      }
    }
    $tax:
    array(1) {
      ["company"]=>
      array(1) {
        [0]=>
        string(5) "Takii"
      }
    }

    Thread Starter dalemoore

    (@dalemoore)

    If I turn on the debugger and upload, I get this:

    $is_update:
    bool(true)
    $post:
    array(8) {
      ["post_type"]=>
      string(5) "plant"
      ["ID"]=>
      string(2) "68"
      ["post_name"]=>
      string(27) "lobularia-blushing-princess"
      ["post_author"]=>
      int(41)
      ["post_date"]=>
      string(19) "2015-01-12 19:48:00"
      ["post_status"]=>
      string(7) "publish"
      ["post_title"]=>
      string(29) "Lobularia 'Blushing Princess'"
      ["post_content"]=>
      string(139) "Sprayed 3 times to control spider mite damage.
    
    This is a test on Lobularia. Does it update from the spreadsheet?
    
    Fertilized once a month."
    }
    $meta:
    array(1) {
      ["cfs_plant_ratings"]=>
      array(2) {
        ["plant_rating_values"]=>
        string(1) "5"
        ["plant_rating_dates"]=>
        string(10) "2014-06-12"
      }
    }
    $tax:
    array(1) {
      ["company"]=>
      array(1) {
        [0]=>
        string(14) "Proven Winners"
      }
    }
    $is_update:
    bool(true)
    $post:
    array(8) {
      ["post_type"]=>
      string(5) "plant"
      ["ID"]=>
      string(2) "71"
      ["post_name"]=>
      string(8) "marigold"
      ["post_author"]=>
      int(41)
      ["post_date"]=>
      string(19) "2015-01-20 20:02:00"
      ["post_status"]=>
      string(7) "publish"
      ["post_title"]=>
      string(8) "Marigold"
      ["post_content"]=>
      string(74) "Sprayed 3 times to control spider mite damage.
    
    Fertilized once a month."
    }
    $meta:
    array(1) {
      ["cfs_plant_ratings"]=>
      array(2) {
        ["plant_rating_values"]=>
        string(3) "3.5"
        ["plant_rating_dates"]=>
        string(10) "2014-12-29"
      }
    }
    $tax:
    array(1) {
      ["company"]=>
      array(1) {
        [0]=>
        string(4) "Ball"
      }
    }
    $is_update:
    bool(true)
    $post:
    array(8) {
      ["post_type"]=>
      string(5) "plant"
      ["ID"]=>
      string(2) "73"
      ["post_name"]=>
      string(5) "vinca"
      ["post_author"]=>
      int(41)
      ["post_date"]=>
      string(19) "2015-01-20 20:13:00"
      ["post_status"]=>
      string(7) "publish"
      ["post_title"]=>
      string(5) "Vinca"
      ["post_content"]=>
      string(74) "Sprayed 3 times to control spider mite damage.
    
    Fertilized once a month."
    }
    $meta:
    array(1) {
      ["cfs_plant_ratings"]=>
      array(2) {
        ["plant_rating_values"]=>
        string(3) "3.5"
        ["plant_rating_dates"]=>
        string(10) "2014-05-11"
      }
    }
    $tax:
    array(1) {
      ["company"]=>
      array(1) {
        [0]=>
        string(6) "Sakata"
      }
    }
    $is_update:
    bool(true)
    $post:
    array(8) {
      ["post_type"]=>
      string(5) "plant"
      ["ID"]=>
      string(2) "75"
      ["post_name"]=>
      string(7) "petunia"
      ["post_author"]=>
      int(41)
      ["post_date"]=>
      string(19) "2015-01-21 20:13:00"
      ["post_status"]=>
      string(7) "publish"
      ["post_title"]=>
      string(7) "Petunia"
      ["post_content"]=>
      string(90) "Sprayed 3 times to control spider mite damage.
    
    This is Petunia.
    
    Fertilized once a month."
    }
    $meta:
    array(1) {
      ["cfs_plant_ratings"]=>
      array(2) {
        ["plant_rating_values"]=>
        string(1) "5"
        ["plant_rating_dates"]=>
        string(10) "2015-02-12"
      }
    }
    $tax:
    array(1) {
      ["company"]=>
      array(1) {
        [0]=>
        string(5) "Takii"
      }
    }
    All Done.

    Even though it just says “Import CSV 1.” when I disable the debug plugin.

    Thread Starter dalemoore

    (@dalemoore)

    Hi Takuro, sorry for the delayed response. Work was canceled two days in a row due to weather.

    I’ve tried your code above, but unfortunately it didn’t work. When I import the CSV, all I see is this.

    My CSV is here, if this might help?

    Thread Starter dalemoore

    (@dalemoore)

    I’m at home now and don’t have access, but this is from memory using your code (placed in my theme’s functions.php):

    function rsci_meta_filter( $meta, $post, $is_update ) {
    
        // Create containers
        $meta_array = array();
        $repeater_array = array();
    
        foreach ($meta as $key => $value) {
     // if key matches cfs_plant_rating_values column in CSV
            if ($key == 'cfs_plant_rating_values') {
    $repeater_array[0]['plant_rating_values'] = $value; // actual CFS field is plant_rating_values
            } elseif ($key == 'cfs_plant_rating_dates') {
                $repeater_array[1]['plant_rating_dates'] = $value;
            } else { // Pass through normal (not CFS) custom field data
                $meta_array[$key] = $value;
            }
        }
    
        // Insert Repeater data
        $meta_array['plant_rating'] = $repeater_array;
    
        return $meta_array;
    
    }
    add_filter( 'really_simple_csv_importer_save_meta', 'rsci_meta_filter', 10, 3 );

    Thanks so much for your help.

    Thread Starter dalemoore

    (@dalemoore)

    Hm, having trouble getting it to work. In your example at https://notnil-creative.com/blog/archives/2913 the repeater is made up of multiple columns, while mine is made of two columns with comma-separated values in a cell per post. Having some trouble wrapping my head around how to break it apart. I assume I need to use something similar to the ‘select’ example to break the comma-separated values apart, and then recombine them?

    Using your debug add-on, after uploading CSV I’m getting:

    array(2) {
      ["custom_field"]=>
      string(0) ""
      ["plant_rating"]=>
      array(2) {
        [0]=>
        array(1) {
          ["plant_rating_dates"]=>
          string(54) "2014-12-05,2015-01-04,2015-01-10,2015-01-20,2015-02-12"
        }
        [1]=>
        array(1) {
          ["plant_rating_values"]=>
          string(11) "4,3.5,2,4,5"
        }
      }
    }

    When, if I manually add the rows in CFS and print_r, it looks like:
    Array ( [0] => Array ( [plant_rating_values] => 4 [plant_rating_dates] => 2014-12-05 ) [1] => Array ( [plant_rating_values] => 3.5 [plant_rating_dates] => 2015-01-04 ) [2] => Array ( [plant_rating_values] => 2 [plant_rating_dates] => 2015-01-10 ) [3] => Array ( [plant_rating_values] => 2015-01-20 [plant_rating_dates] => 4 ) [4] => Array ( [plant_rating_values] => 2015-02-12 [plant_rating_dates] => 5 ) )

    I’m still learning PHP… arrays confuse me.

    Thread Starter dalemoore

    (@dalemoore)

    Thanks Takuro.

    foreach ($meta as $key => $value) {
    
        // If custom field name is "plant_rating"
        if ($key == 'cfs_plant_rating_values') {
          $repeater_array[0]['plant_rating_values'] = $value;
        } elseif ($key == 'cfs_plant_rating_dates') {
          $repeater_array[1]['plant_rating_dates'] = $value;
        }
    
      } // end foreach loop
    
      // Insert Repeater data
      $meta_array['cfs_plant_rating'] = $repeater_array;

    Should I be using the cfs_ prefix?

    Thread Starter dalemoore

    (@dalemoore)

    I just downloaded it and installed, but it won’t let you export Custom Post Types. It directs you to add-ons on the website Gumroad, of which are no longer available.

    Thread Starter dalemoore

    (@dalemoore)

    Thanks, Takuro! I’ll give it a try.

    dalemoore

    (@dalemoore)

    Could this be used to update based on the slug/post name, instead of post ID?

    dalemoore

    (@dalemoore)

    I can confirm this happens on all of my sites as well. When creating a new site, the Google map covers the fields in the add location area. This is in Chrome.

    Thread Starter dalemoore

    (@dalemoore)

    Okay, thanks for the info. I will keep it on recently added for the time being until fixed.

    The Responsive Slider plugin has a default stylesheet, and in it they are adding 30px bottom margin on responsive-slider.flexslider. The below should fix it:

    .responsive-slider.flexslider {
       margin-bottom: 0px; /* add !important if it still won't work */
    }
Viewing 15 replies - 16 through 30 (of 66 total)