Jump to content

jarvis

Members
  • Posts

    543
  • Joined

  • Last visited

Everything posted by jarvis

  1. Hi cyberRobot Thanks for the reply. Basically, I'm trying to grab the values from a submitted form and pass them into an array. I'm making progress and now have: $attributes = array( 'pa_car-make' => array_shift( wc_get_product_terms( $post_id , 'pa_car-make', array( 'fields' => 'names' ) ) ), 'pa_no-of-doors' => array_shift( wc_get_product_terms( $post_id, 'pa_no-of-doors', array( 'fields' => 'names' ) ) ) ); ?><pre><?php print_r($attributes); ?></pre> <?php echo '<hr/>'; $i = 0; // Loop through the attributes array foreach ($attributes as $name => $value) { $product_attributes[$i] = array ( 'name' => htmlspecialchars( stripslashes( $name ) ), // set attribute name 'value' => $value, // set attribute value 'position' => 1, 'is_visible' => 1, 'is_variation' => 0, 'is_taxonomy' => 0, 'row' => $i ); $i++; ?><pre><?php print_r($product_attributes); ?></pre> <?php } But for some odd reason, it shows the first row twice: Array ( [1] => Array ( [name] => pa_car-make [value] => Aston Martin [position] => 1 [is_visible] => 1 [is_variation] => 0 [is_taxonomy] => 0 [row] => 1 ) ) Array ( [1] => Array ( [name] => pa_car-make [value] => Aston Martin [position] => 1 [is_visible] => 1 [is_variation] => 0 [is_taxonomy] => 0 [row] => 1 ) [2] => Array ( [name] => pa_no-of-doors [value] => 3 Doors [position] => 1 [is_visible] => 1 [is_variation] => 0 [is_taxonomy] => 0 [row] => 2 ) ) Which I can't fathom out!? oh and it was my error on the post_id / 1008 you pointed out, it was from me testing
  2. Hi All, Arrays seem to be my downfall so hope someone can help! I have the following: $pa_no_of_doors_value = array_shift( wc_get_product_terms( 1008, 'pa_no-of-doors', array( 'fields' => 'names' ) ) ); echo '<br/>No Of Doors: '.$pa_no_of_doors_value.'<br/>'; $pa_no_of_doors['type'] = array( 'name' => htmlspecialchars(stripslashes('No Of Doors')), 'value' => $pa_no_of_doors_value, 'position' => 1, 'is_visible' => 1, 'is_variation' => 0, 'is_taxonomy' => 0 ); print_r($pa_no_of_doors); echo '<p> </p>'; $pa_car_make_value = array_shift( wc_get_product_terms( $post_id, 'pa_car-make', array( 'fields' => 'names' ) ) ); echo '<br/>Car Make: '.$pa_car_make_value.'<br/>'; $pa_car_make['type'] = array( 'name' => htmlspecialchars(stripslashes('Car Make')), 'value' => $pa_car_make_value, 'position' => 1, 'is_visible' => 1, 'is_variation' => 0, 'is_taxonomy' => 0 ); print_r($pa_car_make); I then use: update_post_meta($post_id, '_product_attributes', $pa_car_make); The above then updates the DB (based on Wordpress). As you can see, this is only updating with one of the options. What I'm trying to do is a foreach loop (as I've got many more add, then pass all of them into the _product_attributes field Having added them via Wordpress and looked at the DB, I can see how it needs to then appear: a:2:{ s:8:"car-make";a:6:{s:4:"name";s:8:"Car Make";s:5:"value";s:12:"Aston Martin";s:8:"position";s:1:"0";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:0;} s:14:"pa_no-of-doors";a:6:{s:4:"name";s:14:"pa_no-of-doors";s:5:"value";s:0:"";s:8:"position";s:1:"1";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;} } So thinking something like: update_post_meta($post_id, '_product_attributes', serialize( $attributes )); But my brain just can't work out how to do a foreach of the various types! Sorry for asking a probably simple question!!
  3. Hi I really hope someone can help me with this. I have the following: $location = (array) ( unserialize(get_post_meta($post_id, $test, true)) ); print_r ($location); This outputs: a:3:{s:7:"address";s:38:"1 Test Way, Test Town, Sussex AB12 3BC, UK";s:3:"lat";d:50.12396349999999932833816274069249629974365234375;s:3:"lng";d:0.1235546000000000272933675660169683396816253662109375;}​ If I do: $test = (unserialize('a:3:{s:7:"address";s:38:"1 Test Way, Test Town, Sussex AB12 3BC, UK";s:3:"lat";d:50.12396349999999932833816274069249629974365234375;s:3:"lng";d:0.1235546000000000272933675660169683396816253662109375;}​')); Then the following works: $geo_address = $test['address']; echo $geo_address; And it displays what I need! Why then does the following not work: $test = (unserialize( get_post_meta($post_id, $test, true) )); Surely its the same thing? Any help is much appreciated!
  4. Thanks Barand. that's more the sort of thing I was after
  5. Hi Muddy_Funster the 125 is the input field name (generated by form code beyond my remit), so the 10 fields would be 124,125...133 I guess I was just wondering if there was a tidier way of coding it rather than what I've gone with Thanks
  6. Hi All I hope someone can help. I know it's easy but for some reason, I simply can't get my head around it. I need to collect values from a form: $gallery_1 = $_POST['item_meta'][124]; $gallery_2 = $_POST['item_meta'][125]; I have up to 10 of the above. I'm then using: $meta_value=$gallery_1.','.$gallery_2....; And so on to $gallery_10 However, this isn't efficient I'm sure and what happens if the 2nd or 8th - 10th input is empty Can I put this into a foreach loop to build up an array of values? Thanks
  7. Ah thanks Psycho, will try option 1 Thanks again
  8. Ah think I'm getting somewhere (typical after posting on here and a day of hair pulling) I've changed the code to $meta_value = serialize(array( 'address' => $full_address, 'lat' => $lat, 'lng' => $lng )); Which has resolved the warning. But now adds \\ which I need to remove. For example; a:3:{s:7:"address";s:55:"1 test road, Test town, Test County ab12 3cd, UK";s:3:"lat";d:50.123456;s:3:"lng";d:0.123456;} How would I remove those?
  9. Hi all, I'm running an update sql query from my wordpress functions file when a form is submitted. This grabs the address fields, uses the Google API and gets the lat and lng co-ords so I can utilise these elsehwere. My issue is the warning I get when I submit the form. My codes below: $meta_value = array( 'address' => $full_address, 'lat' => $lat, 'lng' => $lng ); #$location = array($full_address,$lat,$lng); print_r($meta_value); $wpdb->show_errors(); #$wpdb->update( $table, $data, $where ); $wpdb->update( $wpdb->postmeta, array( 'meta_value' => $meta_value ), array( "meta_key" => 'location', "post_id" => $post_id )); $wpdb->print_error(); var_dump( $wpdb->last_query ); However, when it runs, I get the warning: Warning: mysql_real_escape_string() expects parameter 1 to be string, It should pass in the values from the Array: Array ( [address] => Address 1, Town, County AB12 3CD, United kingdom [lat] => 50.123456 [lng] => 0.1234567 ) I can't see for looking now so any help is much appreciated!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.