Jump to content

jarvis

Members
  • Posts

    543
  • Joined

  • Last visited

Posts posted by jarvis

  1. 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:

    echo '<script type="text/javascript" id="getme">
    								//<![CDATA[
    								jQuery(document).ready(function(){						
    									new jPlayerPlaylist({
    										jPlayer: "#jquery_jplayer_' . $unique_id . '",
    										cssSelectorAncestor: "#jp_container_' . $unique_id . '"
    									},[';
    										foreach( $urls as $id=>$file ):
    											echo '{';
    											echo 'title: "'.addslashes( $file['title'] ).'",';
    											echo $file['extension'] . ': "' . addslashes( $file['url'] ) . '"';
    											echo '}';
    											if ( $id <> count($urls)-1 ) {
    												echo ',';
    											}
    										endforeach;
    					echo '		], {
    										noConflict: "jQuery",
    										swfPath: "' . plugins_url( 'assets/js/jQuery.jPlayer.2.4.0' , __FILE__ ) . '",
    										cssSelectorAncestor: "#jp_container_'.$unique_id.'",
    										supplied: "' . implode( ',', $ext ) . '",
    										solution: "' . ( $admin_options['woo_jplayer_solution'] == 'flash' ? 'flash, html' : 'html, flash' ) . '",
    										loop: ' . ( $admin_options['woo_jplayer_loop'] == 'yes' ? 'true' : 'false' ) . '
    									});
    								});
    								//]]>
    							</script>';
    

    Which is called in a PHP file. So can I just reference that somehow? 

     

    Apologies if this is a basic question!

  2. 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

  3. 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

  4. 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?

  5. @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-doors

     

    And 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

  6. 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!

  7. 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

  8. 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

  9. 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

  10. 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!!

  11. 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!

  12. 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

  13. 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

  14. 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?

  15. 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!

  16. 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:

     

     

     

     

      meta_id post_id meta_key meta_value meta_id post_id meta_key meta_value meta_id post_id meta_key meta_value 2729 430 _tribe_wooticket_event 263 2728 430 _tribe_wooticket_order 427 2703 427 1 Attendee Name John Smith 2729 430 _tribe_wooticket_event 263 2728 430 _tribe_wooticket_order 427 2706 427 2 Attendee Name Martin Frank 2729 430 _tribe_wooticket_event 263 2728 430 _tribe_wooticket_order 427 2709 427 3 Attendee Name Chris B Bacon 2725 429 _tribe_wooticket_event 263 2724 429 _tribe_wooticket_order 427 2703 427 1 Attendee Name John Smith 2725 429 _tribe_wooticket_event 263 2724 429 _tribe_wooticket_order 427 2706 427 2 Attendee Name Martin Frank 2725 429 _tribe_wooticket_event 263 2724 429 _tribe_wooticket_order 427 2709 427 3 Attendee Name Chris B Bacon 2721 428 _tribe_wooticket_event 263 2720 428 _tribe_wooticket_order 427 2703 427 1 Attendee Name John Smith 2721 428 _tribe_wooticket_event 263 2720 428 _tribe_wooticket_order 427 2706 427 2 Attendee Name Martin Frank 2721 428 _tribe_wooticket_event 263 2720 428 _tribe_wooticket_order 427 2709 427 3 Attendee Name Chris B Bacon 2661 424 _tribe_wooticket_event 263 2660 424 _tribe_wooticket_order 416 2530 416 1 Attendee Name John Smith 2661 424 _tribe_wooticket_event 263 2660 424 _tribe_wooticket_order 416 2533 416 2 Attendee Name Fred Bloggs 2661 424 _tribe_wooticket_event 263 2660 424 _tribe_wooticket_order 416 2536 416 3 Attendee Name Bob Squrepants 2657 423 _tribe_wooticket_event 263 2656 423 _tribe_wooticket_order 416 2530 416 1 Attendee Name John Smith 2657 423 _tribe_wooticket_event 263 2656 423 _tribe_wooticket_order 416 2533 416 2 Attendee Name Fred Bloggs 2657 423 _tribe_wooticket_event 263 2656 423 _tribe_wooticket_order 416 2536 416 3 Attendee Name Bob Squrepants 2653 422 _tribe_wooticket_event 263 2652 422 _tribe_wooticket_order 416 2530 416 1 Attendee Name John Smith 2653 422 _tribe_wooticket_event 263 2652 422 _tribe_wooticket_order 416 2533 416 2 Attendee Name Fred Bloggs 2653 422 _tribe_wooticket_event 263 2652 422 _tribe_wooticket_order 416 2536 416 3 Attendee Name Bob Squrepants 2646 421 _tribe_wooticket_event 263 2645 421 _tribe_wooticket_order 420 2636 420 1 Attendee Name John Smith 2595 419 _tribe_wooticket_event 263 2594 419 _tribe_wooticket_order 417 2578 417 1 Attendee Name Chris B Bacon 2595 419 _tribe_wooticket_event 263 2594 419 _tribe_wooticket_order 417 2581 417 2 Attendee Name AN Other 2591 418 _tribe_wooticket_event 263 2590 418 _tribe_wooticket_order 417 2578 417 1 Attendee Name Chris B Bacon 2591 418 _tribe_wooticket_event 263 2590 418 _tribe_wooticket_order 417 2581 417 2 Attendee Name AN Other

     

    Please let me know if you need anything else

     

    export-BXzfCZN3.gif - http://picpaste.com/export-BXzfCZN3.gif

  17. 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!!!

     

×
×
  • 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.