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!
  10. Thanks Barand, that's got me more or less there (apologies for the delay getting back to you too!)
  11. Sorry I'm trying to paste but it loses the formatting...
  12. Hi Barand, Sure, no problem. is this any good: SELECT * FROM $wpdb->postmeta pm, $wpdb->postmeta pm1, $wpdb->postmeta pm2 WHERE pm.meta_key = '_tribe_wooticket_event' AND pm.meta_value =263 AND pm1.meta_key = '_tribe_wooticket_order' AND pm.post_id = pm1.post_id AND pm2.meta_key LIKE '% Attendee Name' AND pm1.meta_value = pm2.post_id ORDER BY `pm1`.`post_id` DESC LIMIT 0 , 30 Produces: Please let me know if you need anything else - http://picpaste.com/export-BXzfCZN3.gif
  13. Thanks Barand, unfortunately, that returns 0 results Thank you for your time though
  14. Hi All, I really hope someone can help. Am a novice a this stuff and spent ages getting no where. I hope this makes some sort of sense... I currently have the following MySQL statement: SELECT pm1.meta_value AS 'ORDER No', pm1.post_id AS 'TICKET No' FROM $wpdb->postmeta pm, $wpdb->postmeta pm1 WHERE pm.meta_key = '_tribe_wooticket_event' AND pm.meta_value =263 AND pm1.meta_key = '_tribe_wooticket_order' AND pm.post_id = pm1.post_id ORDER BY `pm1`.`post_id` DESC This returns the following: ORDER No TICKET No 427 430 427 429 427 428 416 424 416 423 416 422 420 421 417 419 417 418 Basically, 1 order (427) can contain 3 tickets (430,429,428) - for example! I then have another MySQL query: SELECT pm.post_id AS 'Order No', pm.meta_value AS 'Guest Name' FROM $wpdb->postmeta pm WHERE pm.post_id = '427' AND pm.meta_key LIKE '% Attendee Name' LIMIT 0 , 30 This returns the following: Order No Guest Name 427 John Smith 427 Fred Bloggs 427 AN Other What I need to do, is somehow combine the 2 statements so I end up with ORDER No TICKET No Guest Name 427 430 John Smith 427 429 Fred Bloggs 427 428 AN Other 416 424 Guest A 416 423 Guest B 416 422 Guest C Not sure if it helps but whenever a Name is added, it stores like so: Meta Key Meta Value 1 Attendee Name John Smith 2 Attendee Name Fred Bloggs 3 Attendee Name AN Other Any help on this would be much appreciated! Thanks in advanced!!!
  15. Hi All, I hope someone can help! I've got some code that passes an array of values via an ajax call. This works fine and I can see my values in the specified div: $("#container").html(data); What I'd like to do, is get that info and pass it to a cookie. However, I'm struggling a tad. I currently have this: var set_me = html(data); $.cookie('choice',set_me, {expires: 7, path: '/'}); alert( $.cookie("choice") ); But sadly it's not working. I think it's something simple but this is new to me some need some help please Thanks
  16. Hi All, Am sure this is simple but can't work it out. I have the following which creates 3 menus: <p>Drag items from one menu to another</p> <table> <tr> <td valign="top">Menu 1</td> <td valign="top">Menu 2</td> <td valign="top">Menu 3</td> </tr> <tr> <td valign="top"> <ul class="sortable" id="menu1"> <li id="id_1">Item 1</li> <li id="id_2">Item 2</li> </ul> </td> <td valign="top"> <ul class="sortable" id="menu2"> <li id="id_3">Item 3</li> <li id="id_4">Item 4</li> </ul> </td> <td valign="top"> <ul class="sortable" id="menu3"> <li id="id_5">Item 5</li> <li id="id_6">Item 6</li> </ul> </td> </tr> </table> This uses the following to show an array of each menu: $(function() { $("ul.sortable").sortable({ connectWith: '.sortable', update: function(event, ui) { $('#menu_choice').empty().html( $('.sortable').serial() ); } }); }); (function($) { $.fn.serial = function() { var array = []; var $elem = $(this); $elem.each(function(i) { var menu = this.id; $('li', this).each(function(e) { array.push( menu + '['+e+']=' + this.id ); }); }); return array.join('&'); } })(jQuery); What I'd like is to simply grab the values of menu 1 only, as the array shows all menus. What am I doing wrong as can't seem to just return menu1. Going forward, I then want to store the returned array into a PHP cookie if this is possible? Many thanks
  17. Ok, changing: $the_team = (isset($_POST['post_id'])) ? $_POST['post_id'] : 0; To: $the_team = $_POST['post_id']; Works but can I check this is the correct thing to do and isn't some glitchy fix?
  18. Thanks Fastsol, It does echo out an ID, if I view the source I can see rel="1" Within my main JS call, I've added: alert(work_post_id); Which when I click the link, get the pop up with a 1 in it. So can see it's getting the value. It just seems to fail to pass it to the script, so guessing this is where the issue is but can't see why
  19. Ok, making progress! My script now looks like: $(".team-link").click(function(){ var post_id = $(this).attr("rel"); $.ajax({ url : "http://www.domain.co.uk/wp-content/themes/name/loop.php", data : {the_team: post_id}, type : "POST", dataType : "html", success: function(data) { alert("success"); $("#single-post-container").html(data); }, error: function (jqXHR, textStatus, errorThrown) { $("#temp_load").remove(); alert(jqXHR + " :: " + textStatus + " :: " + errorThrown); } }); }); It returns the success message but not getting the ID. Sorry to post in small amounts but seems to help the thought process. Just think I'm missing the total obvious now LOL
  20. I also noticed an error in my js file, so it now looks like this: $.ajaxSetup({cache:false}); $(".team-link").click(function(){ var post_id = $(this).attr("rel"); $.ajax({ url : "http://www.domain.co.uk/wp-content/themes/name/loop.php", data : {"the_team": post_id }, type : "POST", dataType : "html", success: function(response) { alert("success"); $("#single-post-container").html(response); }, error: function (jqXHR, textStatus, errorThrown) { $("#temp_load").remove(); alert(jqXHR + " :: " + textStatus + " :: " + errorThrown); } }); }); Unfortunately, it still isn't working
  21. Thanks Psycho for the prompt reply. I've tried as both POST and GET in each file but to no avail. It was a copy and paste error above. They were set as GET I've also placed an ELSE statement in loop for testing as suggested. Is there anything else I can try?
  22. Hi All, Am hoping someone can point out my perhaps obvious issue here. I've a series of links that are dynamically created: <a class="team-link" rel="<?php the_ID(); ?>" href="#"> When a link is clicked, I'm trying to get content to load into this DIV: <div id="single-post-container"></div> I have the following jquery: <script> $(document).ready(function(){ $.ajaxSetup({cache:false}); $(".team-link").click(function(){ var post_id = $(this).attr("rel"); $.ajax({ url : "http://www.domain.co.uk/wp-content/themes/name/loop.php", data : {"the_team": post_id }, type : "POST", dataType : "html", success: function(response) { $("#single-post-container").html(response); } return false; }); }); </script> This is my loop.php file: require_once('../../../wp-load.php'); // Our variables $the_team = (isset($_GET['post_id'])) ? $_GET['post_id'] : 0; echo $the_team; query_posts(array( 'post_type' => 'work', 'meta_key' => 'author_name', 'meta_value' => $the_team )); // our loop if (have_posts()) { while (have_posts()){ the_post(); ?> <h1><?php the_title(); ?></h1> <?php the_content(); ?> <hr /> <?php } } wp_reset_query(); However, when you click the link, nothing happens. I know loop.php works as I can specify a value and manually browse to it to see the content. I feel I'm missing something obvious as I'm new to AJAX. Your help/patience is very much appreciated
  23. Thanks This is in my header file: <?php $cookie_name = 'defaultLanguage'; // set cookie only when the url contains a value if(isset($_GET['language'])){ // note: you should validate $_GET['language'] to insure it contains exactly only one of the permitted values before using it at all setcookie($cookie_name, $_GET['language'], time() + (86400 * 30), '/'); // 86400 = 1 day } /** * @package WordPress **/ get_header(); include(TEMPLATEPATH."/path.php"); ?> <!DOCTYPE html> <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]--> <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]--> <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> <head> This is a wordpress theme but the site calls this file in so shouldn't be an issue Thanks for your time/assistance, it's really appreciated!
  24. Sorry to add to this but I can't seem to get the cookie to save? If I change page or refresh, the cookie seems to revert back to English It's the first piece of code in the header.php file which is used by all my template pages. Any further pointers are much appreciated!
  25. Thank you @mac_gyver That's spot on. I've a question though if you'd be so kind. If I do print 'Cookie value "' . $_COOKIE[$cookie_name]; If I've not set anything, how come it doesn't show English?
×
×
  • 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.