Posts

Get wordpress posts and featured Image via direct sql query

Use below MySql query to get wordpress posts with featured image SELECT p1 .*, wm2 . meta_value FROM wp_posts p1 LEFT JOIN wp_postmeta wm1 ON ( wm1 . post_id = p1 . id AND wm1 . meta_value IS NOT NULL AND wm1 . meta_key = "_thumbnail_id" ) LEFT JOIN wp_postmeta wm2 ON ( wm1 . meta_value = wm2 . post_id AND wm2 . meta_key = "_wp_attached_file" AND wm2 . meta_value IS NOT NULL ) WHERE p1 . post_status = "publish" AND p1 . post_type = "post" ORDER BY p1 . post_date DESC

add join in datatables using codeigniter

Sets join statement variables. If you want DataTables to include data from another table, you can define an a table along with its columns and foreign key relationship. $this->datatables->join('states', 'cities.state_id = states.id', 'left'); $this->datatables->select('cities.id,cities.name,states.name as state_name') ->from('cities'); 

Add minimum charge in Woocommerce cart page

// Paste below code in your active theme s functions.php add_action( 'woocommerce_cart_calculate_fees', ' wc_add_minimum_fee ' ); function wc_add_minimum_fee (){ global $woocommerce; $stotal = $woocommerce->cart->subtotal; if ($ stotal < 999 ) { $surcharge = 100; } else { $surcharge = 0; } $woocommerce->cart->add_fee( __('Surcharge', 'woocommerce'), $surcharge ); }

Login with email or username in codeigniter

function login_user() { $email= $this->input->post('email'); $password= MD5($this->input->post('password')); $this->db->where("(Email='$email' OR Username='$email') AND Password='$password' "); $Query = $this->db->get('users'); if($Query->num_rows() > 0) { return $Query->row(); } else { return false; } }

Convert JSON string to Array in php

$json_string = '{ "title": "PHP: The Definitive Guide", "author": "Arun Verma", }' ; $res = json_decode ( $json , true ) ; echo $res [ 'title' ] ; // PHP: The Definitive Guide

Install XAMPP 1.8.3-4 on Ubuntu 32 bit

Step 1: Paste below code to ubuntu terminal to Download the installer.             wget http://downloads.sourceforge.net/project/xampp/XAMPP%20Linux/1.8.3/xampp-linux-1.8.3-4-installer.run Step 2: Run the installer             sudo chmod +x xampp-linux-1.8.3-4-installer.run           sudo ./xampp-linux-1.8.3-4-installer.run Step 3: Follow the xampp installation setup screen

Remove last comma from string in php

$string = "Bar, Restaurant, Take Away Food, Dive School, Hotel,"; rtrim($string, ","); or   You can use substr( $string, 0, -1);