Posts

Showing posts from August, 2018

Avarage Comment rating in wordpress

<?php /* Avarage Comment rating  */ function average_rating() {     global $wpdb;     $post_id = get_the_ID();     $ratings = $wpdb->get_results("         SELECT $wpdb->commentmeta.meta_value         FROM $wpdb->commentmeta         INNER JOIN $wpdb->comments on $wpdb->comments.comment_id=$wpdb->commentmeta.comment_id         WHERE $wpdb->commentmeta.meta_key='rating'         AND $wpdb->comments.comment_post_id=$post_id         AND $wpdb->comments.comment_approved =1         ");     $counter = 0;     $average_rating = 0;        if ($ratings) {         foreach ($ratings as $rating) {             $average_rating = $average_rating + $rating->meta_value;       ...

get lat and long from address in php

<?php $address = '907, Sneh Nagar, Sapna Sangeeta Road, Opp. Navlakha Complex D Block, Indore'; $url = 'http://maps.google.com/maps/api/geocode/json?address='.urlencode($address).'&sensor=false&region=England'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_PROXYPORT, 3128); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $response = curl_exec($ch); curl_close($ch); $response = json_decode($response); $lat = $response->results[0]->geometry->location->lat; $long = $response->results[0]->geometry->location->lng;  echo $lat; echo '<br>'; echo $long;     ?>

custom meta fields for specific page template in wordpress

/**  * Add About Us custom fields  */ function add_about_meta_boxes() {   add_meta_box("about_content_meta", "About Content", "add_about_content_about_content_meta", "page", "normal", "low");   } function add_about_content_about_content_meta() { global $post; $custom = get_post_custom( $post->ID );         $pageTemplate = get_post_meta($post->ID, '_wp_page_template', true);         if($pageTemplate == 'about-page-template.php' )         { ?> <style>.width99 {width:99%;}</style> <p> <label>Our Mission:</label><br /> <textarea rows="5" name="our_mission" class="width99"><?= @$custom["our_mission"][0] ?></textarea> </p>     <p> <label>Our Vission:</label><br /> <textarea rows="5" name="our_vission" class="width99...

http change to https using javascript

var  url= url.replace(/^http:\/\//i, 'https://'); var storeUrl= storeUrl.replace(/^http:\/\//i, 'https://');

checkbox value get in j query on checked

jQuery(".our_course").click(function(){         var selectedCountry = new Array();         var n = jQuery(".our_course:checked").length;         if (n > 0){             jQuery(".our_course:checked").each(function(){                 selectedCountry.push($(this).val());             });         }         alert(selectedCountry);     }); Reference:   https://stackoverflow.com/questions/2834350/get-checkbox-value-in-jquery

get product gallery by product id in wordpress

 $product_id = '62';     $product = new WC_product($product_id);     $attachment_ids = $product->get_gallery_attachment_ids();     foreach( $attachment_ids as $attachment_id )         {           // Display the image URL           echo $Original_image_url = wp_get_attachment_url( $attachment_id );           // Display Image instead of URL         // echo wp_get_attachment_image($attachment_id, 'full');         }