jarvis
-
Posts
543 -
Joined
-
Last visited
Posts posted by jarvis
-
-
Hi All
I wonder if someone can help!
I've a piece of javascript that gets generated into a page dynamically.
When the page content initially loads, the script runs. However, due to the way the site is built (ajax), when you go to the next page, the script is added but isn't triggered.
I've fixed all issues whereby I can reference a js file, however, is there anyway to use jQuery.getScript on a script that doesn't have a js file?
I thought I could add a class or ID into the script tag:
<script type="text/javascript" id="getme">
Then use:
jQuery('#getme').remove
To remove it, as I understand you should. Then I need to reload it.
I tried:
jQuery('#getme').reload();
But I think I need to use jQuery.getScript but can't see how to do this on an inline script (rather than a dedicated js file)
Any help is much appreciated
-
Hi All,
I use <div id="player"></div> on a web page.
Then I use:
<script> $('#player').load('http://www.domain.com/jplayer.htm'); </script>
This file contains an MP3 player and quite happily does its thing by outputting the player on the main site. The thing I can't work out, if you refresh the site or click to another page, it reloads the jplayer.htm file and therefore interrupts the music.
Is there a way around this at all?
Thanks
-
Thanks again and apologies for troubling you! Have a good day!!!
-
Thanks cyberRobot!
I came up with this:
$attribute_taxonomies = wc_get_attribute_taxonomies(); if ( $attribute_taxonomies ) : $taxonomyOfInterest = array(); foreach ($attribute_taxonomies as $tax=>$tax_value) : #echo "Key=" . $tax . ", Value=" . $tax_value->attribute_name.'<br/>'; #debug $taxonomyOfInterest[] = 'pa_'.$tax_value->attribute_name; endforeach; endif; #print_r($taxonomyOfInterest);
Is this acceptable or have I overcomplicated something?
-
@cyberRobot
Thanks again for your help yesterday!
I know the last post you sent was to help prevent repetition by using this code:
$taxonomyOfInterest = array( 'pa_car-make', 'pa_no-of-doors', ); $attributes = array(); foreach($taxonomyOfInterest as $currTaxonomy) { $attributes[$currTaxonomy] = array_shift( wc_get_product_terms( $post_id , $currTaxonomy, array( 'fields' => 'names' ) ) ); }
I've managed to get a loop of all the attributes I need that are being manually typed in the first part:
$taxonomyOfInterest = array( 'pa_car-make', 'pa_no-of-doors', );
This block of code produces the inner part:
$attribute_taxonomies = wc_get_attribute_taxonomies(); if ( $attribute_taxonomies ) : foreach ($attribute_taxonomies as $tax) : echo esc_html(wc_attribute_taxonomy_name($tax->attribute_name)).'<br/>'; endforeach; endif;
Which produces:
pa_car-make
pa_no-of-doorsAnd any others in the CMS, so negates having to add them into the code manually. However, I'm struggling to see how I can effectively do this:
$taxonomyOfInterest = array( $attribute_taxonomies = wc_get_attribute_taxonomies(); if ( $attribute_taxonomies ) : foreach ($attribute_taxonomies as $tax) : esc_html(wc_attribute_taxonomy_name($tax->attribute_name)) endforeach; endif; );
Or is this not possible?
Thanks again
-
oh wow! That's really helpful, thanks so much!
-
Thanks @cyberRobot
That seems to have sorted it! Final code:
$pa_no_of_doors_value = array_shift( wc_get_product_terms( $post_id, 'pa_no-of-doors', array( 'fields' => 'names' ) ) ); $pa_car_make_value = array_shift( wc_get_product_terms( $post_id, 'pa_car-make', array( 'fields' => 'names' ) ) ); $attributes = array( 'pa_car-make' => $pa_no_of_doors_value, 'pa_no-of-doors' => $pa_car_make_value, ); $i = 0; // Loop through the attributes array foreach ($attributes as $name => $value) { if(!empty($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 ); $i++; } } print_r($product_attributes);
Thanks for all your help!
-
Oh I see, yes that makes more sense.
As I need to set up loads of attributes, I need to test which ones have a value and only add them into the main loop if that makes sense? So it's not just testing 1 input field
-
Thanks again.
Using:
$attributes = array( if(empty($attributes['pa_no-of-doors'])) { 'no-of-doors' => $pa_no_of_doors_value = array_shift( wc_get_product_terms( $post_id, 'pa_no-of-doors', array( 'fields' => 'names' ) ) ); } if(empty($attributes['pa_car-make'])) { 'car-make' => $pa_car_make_value = array_shift( wc_get_product_terms( $post_id, 'pa_car-make', array( 'fields' => 'names' ) ) ); } );
Gives an error:
Parse error: syntax error, unexpected 'if' (T_IF), expecting ')'
Which points to line:
if(empty($attributes['pa_no-of-doors'])) {
But I've a feeling I've just misunderstood?
Thanks again and apologies
-
Ah! Of course - thank you
With regards to:
$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' ) ) ) );
Is it possible to check if the value is empty? As I know the following isn't possible:
$attributes = array( if(isset($_POST['item_meta'][132])){ $pa_no_of_doors_value = array_shift( wc_get_product_terms( $post_id, 'pa_no-of-doors', array( 'fields' => 'names' ) ) ); if(isset($_POST['item_meta'][242])){ $pa_car_make_value = array_shift( wc_get_product_terms( $post_id, 'pa_car-make', array( 'fields' => 'names' ) ) ); } );
Thanks
-
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
-
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!!
-
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!
-
Thanks Barand. that's more the sort of thing I was after
-
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
-
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
-
Ah thanks Psycho, will try option 1
Thanks again
-
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?
-
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!
-
Thanks Barand, that's got me more or less there (apologies for the delay getting back to you too!)
-
Sorry I'm trying to paste but it loses the formatting...
-
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
-
Thanks Barand, unfortunately, that returns 0 results
Thank you for your time though
-
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 No427 430427 429427 428416 424416 423416 422420 421417 419417 418Basically, 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 Name427 John Smith427 Fred Bloggs427 AN OtherWhat I need to do, is somehow combine the 2 statements so I end up withORDER No TICKET No Guest Name427 430 John Smith427 429 Fred Bloggs427 428 AN Other416 424 Guest A416 423 Guest B416 422 Guest CNot sure if it helps but whenever a Name is added, it stores like so:Meta Key Meta Value1 Attendee Name John Smith2 Attendee Name Fred Bloggs3 Attendee Name AN OtherAny help on this would be much appreciated!Thanks in advanced!!!
jquery getscript by id
in Javascript Help
Posted
Hi Maxxd, many thanks for your reply
I'll be honest, javascript is something i struggle with (yeah I know!)
Can you post an example of what you mean?
This is the script:
Which is called in a PHP file. So can I just reference that somehow?
Apologies if this is a basic question!