Jump to content

jarvis

Members
  • Posts

    543
  • Joined

  • Last visited

Everything posted by jarvis

  1. Thank you cyberRobot! Is there a way around this without compromise to outputting the HTML?
  2. Hi, I'm going mad and in desperation am reaching out for some help. I have a site that outputs a snippet of text (30 words) from a full description (string). The description includes HTML for formatting, which I need to keep in the snippet. My issue is that the snippet never returns 30 words! Below is my code: function limit_words($string, $word_limit) { #$words = explode(" ",$string); $words = preg_split('/\s+/', $string); return implode(" ",array_splice($words,0,$word_limit)); } function limit_words2($string, $word_limit) { $words = explode(" ",$string); #$words = preg_split('/\s+/', $string); return implode(" ",array_splice($words,0,$word_limit)); } $content = " <p><p><strong>LOCATION</strong><br />Centrally located in Kent just of the High Street.</p> <p><strong>ACCOMMODATION</strong><br />231 sq ft.</p> <p><strong>AMENITIES</strong><br />Entry Phone System<br /> Central Heating<br /> Car Parking</p> <p><strong>TERMS</strong><br />A new lease for a term to be agreed.</p> <p><strong>OUTGOINGS</strong><br />To be assessed.</p> <p><strong>VAT</strong><br />All prices and rents are quoted exclusive of VAT. Any intending purchaser or lessee must satisfy themselves as to the incidence of VAT in respect of any transaction.</p> <p><strong>LEGAL COSTS</strong><br />Each party to be responsible for their own legal costs.</p> <p><strong>SERVICE CHARGE</strong><br />Tenant to be responsible for a proportion of costs towards insurance, maintenance and repairs.</p> </p> "; $content2 = " <p><p><strong>LOCATION</strong><br />A shop/office premises to let in Kent, close to NatWest, Holland & Barrett and Fat Face.</p> <p><strong>DESCRIPTION</strong><br />A shop/office premises to let in Kent, close to NatWest, Holland & Barrett and Fat Face.</p> <p><strong>ACCOMMODATION</strong><br />Approximately 159 sq ft. </p> <p><strong>AMENITIES</strong><br />Attractive display window<br /> Laminate floor<br /> Display lighting<br /> Alarm</p> <p><strong>TERMS</strong><br />Easy in easy out terms.</p> <p><strong>OUTGOINGS</strong><br />We understand that the current rateable value is £2550.<br /> Current UBR – 48.2p in £<br /> Small business relief may be available.</p> <p><strong>VAT</strong><br />All prices and rents are quoted exclusive of VAT. Any intending purchaser or lessee must satisfy themselves as to the incidence of VAT in respect of any transaction. The rent is also subject to VAT.</p> <p><strong>LEGAL COSTS</strong><br />Each party responsible for their own legal costs.</p> <p><strong>SERVICE CHARGE</strong><br />Insurance currently £223.32 per annum plus VAT.</p> </p> "; echo limit_words($content,30); echo '<hr>'; echo limit_words($content2,30); echo '<hr>'; echo limit_words2($content,30); echo '<hr>'; echo limit_words2($content2,30); What on earth am I doing wrong? Any help is much appreciated!
  3. Hi All, I'm hoping someone can help! I've got multiple XML files each start and end with a <property> tag I'm trying to merge all files and the following works in terms of merging the files: #Create an array of all file names $files = array(); #Create a function to combine all XML docs function combineXML($file) { global $xmlstr; $xml = simplexml_load_file($file); foreach($xml as $element) $xmlstr .= $element->asXML(); } #Create an XML file for each result foreach ($posts as $post){ $file_name = $post->vebraid.'.xml'; $myfile = fopen($file_name, "w") or die("Unable to open file!"); $content = $post->xml; fwrite($myfile, $content); #Add filename into array of all file names $path = get_stylesheet_directory_uri(); $directory = '/xml/'; $files[]=$path.$directory.$post->vebraid.'.xml'; #Concatenates two or more XML files by creating a string representation of XML elements then reloading string as XML $xmlstr = '<property>'; foreach ($files as $file) combineXML($file); $xmlstr .= '</property>'; #Convert string to XML for further processing $xml = simplexml_load_string($xmlstr); $bytes = file_put_contents("combined.xml", $xml->asXML()); } However, I need to differentiate between each file within the new combined.xml file, ideally adding <prop_detail> around each merged file, for example: <property> <prop_detail> first file contents </prop_detail> <prop_detail> second file contents </prop_detail> <prop_detail> third file contents </prop_detail> </property> I simply can't see how I can introduce this new element Any help is very much appreciated!
  4. Thanks @maxxd, $wpdb->update( $table, $data, $where ); should be commented out - it's for my ref only. Sorry! Thanks for your help though, I think I may leave them as separate queries to run as easier to work with etc.
  5. Hi All, I'm possibly being daft (I blame the heat!). I have the following 2 statements: #Update Site Title $wpdb->show_errors(); $wpdb->update( $table, $data, $where ); $wpdb->update( $wpdb->options, array( 'option_name' => 'blogname', 'option_value' => 'NEW BLOG NAME', 'autoload' => 'yes' ), array( "option_id", $option_id ) ); $wpdb->print_error(); var_dump( $wpdb->last_query ); #Update Site Wide Description $wpdb->show_errors(); $wpdb->update( $table, $data, $where ); $wpdb->update( $wpdb->options, array( 'option_name' => 'blogdescription', 'option_value' => 'MAIN SITE DESCRIPTION GOES HERE', 'autoload' => 'yes' ), array( "option_id", $option_id ) ); $wpdb->print_error(); var_dump( $wpdb->last_query ); As both reside in the same table (options), do I have to run them as separate statements OR is there a way I can run both in one statement? Thanks
  6. Scrap that, I worked it out when I posted and tidied the above - sorry!
  7. Hi, I'm struggling with something which I thought would be very simple. I'm using date_diff to compare to dates, I then wish to run an if statement depending on the difference in days. For example: <?php $date1=date_create("2013-03-15"); $date2=date_create("2013-12-12"); $diff=date_diff($date1,$date2); echo $diff->format("%R%a days"); ?> The output is therefore: "+272 days" ; So why does this not work: $test = $diff->format("%a"); echo $test.'<br>'; if ($test > '250'){ echo 'whoa'; } Am I missing something? Thanks
  8. Thanks @gizmola Apologies for not being clear! Yes, the column with the serialized data is in option_value I need to update 2 parts: 1) email 2) receiver_email The data will not be a constant (i.e. a different email address) but the field name (email and receiver_email) will be constant. The new value will be from $newEmail Does that help? Thanks again
  9. Hi All, I'm really hoping someone can help! I have a table which contains serialised data. I need to run a query which updates 2 elements The table structure is this: `options` (`option_id`, `option_name`, `option_value`, `autoload`) Then within this I have as an example: (1619, 'woocommerce_paypal_settings', ' a:18:{ s:7:"enabled"; s:2:"no"; s:5:"title"; s:6:"PayPal"; s:11:"description"; s:85:"Pay via PayPal; you can pay with your credit card if you don''t have a PayPal account."; s:5:"email"; s:35:"[email protected]"; s:8:"testmode"; s:3:"yes"; s:5:"debug"; s:2:"no"; s:8:"advanced"; s:0:""; s:14:"receiver_email"; s:35:"[email protected]"; s:14:"identity_token"; s:0:""; I need to update email and receiver_email with a new value supplied ($newEmail) I'm not 100% sure but think you have to unserialise, make the amend and re-serialise is that correct? Or is there a better way of handling this? Thanks in advanced
  10. Hi All, I hope someone can help. I currently have the following code: $all_categories = get_categories( $args ); // display a message as the first option $choices = array(array('text' => 'Please Select A Category', 'value' => 0 )); foreach ($all_categories as $cat){ if($cat->category_parent == 0){ $category_id = $cat->term_id; $choices[] = array( 'text' => $cat->name, 'value' => $cat->slug, 'isSelected' => false ); } } $field['choices'] = $choices; As you can see, it loops through a list of results and this is used to construct a drop down The issue I've got, it only returns the top level of categories. In order to get categories and sub categories I need to alter the code to the following: $all_categories = get_categories( $args ); foreach ($all_categories as $cat) { if($cat->category_parent == 0) { $category_id = $cat->term_id; echo $cat->name .'<br/>'; $args2 = array( 'taxonomy' => $taxonomy, 'child_of' => 0, 'parent' => $category_id, 'orderby' => $orderby, 'show_count' => $show_count, 'pad_counts' => $pad_counts, 'hierarchical' => $hierarchical, 'title_li' => $title, 'hide_empty' => $empty ); $sub_cats = get_categories( $args2 ); if($sub_cats) { foreach($sub_cats as $sub_category) { echo ' '.$sub_category->name.'<br/>'; } } } } However, I can't then add the code I need as I now have 2 foreach loops Is there anyway around this?
  11. Thanks @mac_gyver!
  12. Hi Jacques1, That's a fair point but I guess it's the way the wordpress tables handle the info as each wordpress post can have multiple meta hence why I need to search on both those criteria
  13. Hi All, I have the following SQL (which is from Wordpress/WooCommerce): SELECT $wpdb->woocommerce_order_items.order_item_id, $wpdb->woocommerce_order_items.order_id, $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value, $wpdb->users.ID, $wpdb->users.user_nicename, $wpdb->woocommerce_order_itemmeta.meta_key, $wpdb->woocommerce_order_itemmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->users ON $wpdb->postmeta.meta_value = $wpdb->users.ID INNER JOIN $wpdb->woocommerce_order_items ON $wpdb->postmeta.post_id = $wpdb->woocommerce_order_items.order_id INNER JOIN $wpdb->woocommerce_order_itemmeta ON $wpdb->woocommerce_order_items.order_item_id = $wpdb->woocommerce_order_itemmeta.order_item_id WHERE $wpdb->postmeta.meta_key = '_customer_user' AND $wpdb->woocommerce_order_itemmeta.meta_key = '_wcs_migrated_subscription_status' AND $wpdb->woocommerce_order_itemmeta.meta_value = 'active' What I need to do is add another 2 lines at the bottom like so: AND $wpdb->woocommerce_order_itemmeta.meta_key = '_product_id' AND $wpdb->woocommerce_order_itemmeta.meta_value = '20' However, simply adding those 2 lines returns no results, removing those lines returns results yet I know it should have something! Any help is much appreciated
  14. Thanks again maxxd However, as the php creates content within the javascript file, I don't think I can move the inline script into its own javascript file - as far as I know!?
  15. 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!
  16. 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
  17. 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
  18. Thanks again and apologies for troubling you! Have a good day!!!
  19. 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?
  20. @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
  21. oh wow! That's really helpful, thanks so much!
  22. 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!
  23. 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
  24. 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
  25. 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
×
×
  • 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.