Wednesday 16 March 2016

Insert custom post data with custom field using ajax in wordpress

Insert custom post data  with custom field using ajax in wordpress



<!-- This code in your custom template -->

<script>
 jQuery(document).ready(function() {
var form = jQuery( "#newCustomerForm" );


jQuery('.alu1').click(function(){

  var  checkForm = form.valid();
 
  if(checkForm != false){

var newCustomerForm = jQuery('#newCustomerForm').serializeArray();
jQuery.ajax({
url: "<?php bloginfo('wpurl') ?>/wp-admin/admin-ajax.php",
type:'POST',
data: newCustomerForm,
success: function(data){

if(data == "success"){


}
jQuery("form").trigger("reset");
}


});
}
return false;
});
 });
</script>
<form name="test" id="newCustomerForm">
                              <div class="input-group">
                              <span class="input-group-addon"><i class="fa fa-user"></i></span>
                              <input  class="form-control" type="text" placeholder="Enter your name" name="alu_name" required="required" />
                             
                              </div>
                              <div class="input-group">
                              <span class="input-group-addon"><i class="fa fa-envelope-o"></i></span>
                             
                                <input id="exampleInputEmail1" class="form-control" type="email" placeholder="Enter your Email" name="alu_email" required="required" />
                                </div>
                               
                                <div class="input-group">
                              <span class="input-group-addon"><i class="fa fa-mobile"></i></span>
                                <input  class="form-control" type="number" placeholder="Enter your Mobile no" name="alu_mobile" required="required" />
                                </div>
                               
                                <div class="input-group">
                              <span class="input-group-addon"><i class="fa fa-university"></i></span>
                                <input  class="form-control" type="text" placeholder="Enter your city name" name="alu_city" required="required" />
                                </div>
                               
                                <div class="input-group">
                              <span class="input-group-addon"><i class="fa fa-commenting"></i></span>
                                <textarea id="exampleTextarea" class="form-control" rows="3" name="alu_message" required="required"></textarea>
                                </div>
                                <button type="button" class="btn primary alu1">Submit</button>
                                 <input type="hidden" name="submitted" id="submitted" value="true" />
    <input type="hidden" name="nonce" value="<?php echo wp_create_nonce( 'form-nonce' );?>" />  
                            <input type="hidden" name="action" id="my_action" value="my_action" />                   
                                </form>
   
   
   
   
    <?php                           

/** In Your Function File **/
              function myFunction(){
   //do something
  
  
  
 
  

$alu_name=    sanitize_meta('name_alu_c1',$_POST['alu_name'],'user');
$alu_email=    sanitize_email($_POST['alu_email']);
$alu_mobile=    sanitize_meta('phone_alu_c1',$_POST['alu_mobile'],'user');
$alu_city=    sanitize_meta('city_alu_c1',$_POST['alu_city'],'user');
$alu_message=    sanitize_meta('message_alu_c1',$_POST['alu_message'],'user');

$my_cptpost_args = array(
          
            'post_title' => $alu_name,
            'post_status'   => 'publish',
            'post_type' => "alu_contact1",
);
$cpt_id = wp_insert_post($my_cptpost_args, $wp_error );
if($cpt_id){
add_post_meta($cpt_id, 'name_alu_c1', $alu_name, true);//here insert two custom field data.
add_post_meta($cpt_id, 'email_address_alu_c1', $alu_email, true);//here insert two custom field data.
add_post_meta($cpt_id, 'phone_alu_c1', $alu_mobile, true);//here insert two custom field data.
add_post_meta($cpt_id, 'city_alu_c1', $alu_city, true); //here insert two custom field data..
add_post_meta($cpt_id, 'message_alu_c1', $alu_message, true); //here insert two custom field data..

$test = wp_mail( $alu_email, "Contact Us", "Thank You For Contact us" );

echo "success";
}
       
       
   die();
}





add_action('wp_ajax_my_action', 'myFunction');           // for logged in user
add_action('wp_ajax_nopriv_my_action', 'myFunction');    // if user not logged in  

Sunday 13 March 2016

how to add custom column in wordpress categoty or texonomy admin panel in wordpress

how to add custom column in wordpress categoty or texonomy admin panel in wordpress


// product-category is my custom category change your texonomy
add_filter("manage_edit-product-category_columns", 'theme_columns');

function theme_columns($theme_columns) {
    $new_columns = array(
        'cb' => '<input type="checkbox" />',
        'name' => __('Name'),
        'category' => 'Category Banner',
      'description' => __('Description'),
        'slug' => __('Slug'),
        'posts' => __('Posts')
        );
    return $new_columns;
}


add_filter("manage_product-category_custom_column", 'manage_theme_columns', 10, 3);

function manage_theme_columns($out, $column_name, $theme_id) {
    $theme = get_term($theme_id, 'product-category');


global $post;

    switch ($column_name) {
        case 'category':
            // get header image url

           $variable = get_field( 'category_image', 'product-category_'.$theme_id );//here advace customfield value you can use your custom field;
           if(!empty($variable)){
            $out .= "<img src=".$variable." height='83px' width='150px'/>";
   }
            break;

        default:
            break;
    }
    return $out;   
}

How to chnage character lenght and continue reading text in excerpt in wordpress

How to chnage character lenght and continue reading text in excerpt in wordpress


if you have child theme first remove this filter  i have twenty thierteen theme

function child_theme_setup() {
// override parent theme's 'more' text for excerpts
remove_filter( 'excerpt_more', 'twentythirteen_excerpt_more' );

}
add_action( 'after_setup_theme', 'child_theme_setup' );

after change character lenght in wordpress

function et_excerpt_length($length) {
    return 70;
}
add_filter('excerpt_length', 'et_excerpt_length');

you can change the text of continue reading

function et_excerpt_more($more) {
    global $post;
    return '<a href="'. get_permalink($post->ID) . '" class="view-full-post-btn"> read more....</a>';
}
add_filter('excerpt_more', 'et_excerpt_more');

How to Add Js and css In footer in Wordpress

How to Add Js and css In footer in Wordpress


/** Footer add js and css in wordpress
function prefix_add_footer_styles() {

wp_enqueue_script( 'js-name', get_stylesheet_directory_uri() . 'your js path',array('jquery'),'',true);
wp_enqueue_style( 'css-name', get_stylesheet_directory_uri(). 'yor css path' );
  
};
add_action( 'get_footer', 'prefix_add_footer_styles' );

**/

Thursday 10 March 2016

add smooth scrolling using jquery in menu

Hello Here example Add Smooth scroll menu in menu

simple add this js in your page. check it it. it working file

but you need to add jquery.easing.min.js in your header after jquery

jQuery(function() {
    jQuery('a[href*="#"]:not([href="#"])').click(function() {
      if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
        var target = jQuery(this.hash);
        target = target.length ? target : jQuery('[name=' + this.hash.slice(1) +']');
        if (target.length) {
          jQuery('html, body').animate({
            scrollTop: target.offset().top
          }, 1000);
          return false;
        }
      }
    });
  });

Tuesday 16 February 2016

image upload with compress image and add text into image in using php

Hello Here Example Image compress and add text into image

<?php
function compress_image($source_url, $destination_url, $quality) {
  $info = getimagesize($source_url);
if ($info['mime'] == 'image/jpeg') $image = imagecreatefromjpeg($source_url);
elseif ($info['mime'] == 'image/gif') $image = imagecreatefromgif($source_url);
elseif ($info['mime'] == 'image/png') $image = imagecreatefrompng($source_url);
 // Set Path to Font File
$color = imagecolorallocate($image, 255, 255, 255);

//x-coordinate of the upper left corner.
$xPos = 600;
//y-coordinate of the upper left corner.
$yPos = 200;

//Writting the picture
imagestring($image,5,$xPos,$yPos,"Add Your Text Here",$color);
imagejpeg($image, $destination_url, $quality);



return  $destination_url;
}
if(isset($_POST['submit'])){
$tempPath = $_FILES['upload']['tmp_name'];
$mypath = "compress";
if(!is_dir($mypath)){
mkdir($mypath);
}
 $filename = $_FILES['upload']['name'];
 $destination = $mypath."/".$filename;

$destination  =   compress_image($tempPath,$destination,90);
}
?>

<form method="post" enctype="multipart/form-data">

<input type="file" name="upload"/>
<input type="submit" name="submit" value="upload"/>

</form>

Friday 5 February 2016

How to pass variables via PHP CURL

How to pass variables via PHP CURL

$message="Thank you";
$phone = 123456789;
$url = 'http://example.com';


$fields = array('phone'=>$phone,'source'=>'test','message'=>$message);
$fields_string='';


foreach($fields as $key=>$value) {  $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');


$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);

Saturday 30 January 2016

Insert Csv File Data in Mysql using Php with Validation

Insert Csv File Data in Mysql using Php with Validation  Full Example

Sample Csv File Test.csv

<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/jquery.validate.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/additional-methods.min.js"></script>

<script type="application/javascript">
$(document).ready(function(e) {
    $('#pincodeList').validate({
        rules: {
            Csv: {
                required: true,
extension: "xls|csv"
              
            }

        },

    messages: {
        Csv: {
            extension: 'Please upload a csv file!'
        }
}

    });
});
</script>

<?php
include('connect.php');


if($_POST['submit']){
$csv_file = $_FILES['Csv']['name'];
$tmpFilePath =$_FILES['Csv']['tmp_name'];
$newFilePath="pincodeUpload/";
$mypath = "pincodeUpload/".$csv_file;
move_uploaded_file($tmpFilePath, $mypath);
if ( ! is_dir($newFilePath)) {

mkdir($newFilePath);

$csv_file =$mypath;

if (($handle = fopen($csv_file, "r")) !== FALSE) {

   fgetcsv($handle);  
   while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
         $num = count($data);
        for ($c=0; $c < $num; $c++) {
           $col[$c] = $data[$c];
        }

    $col1 = $col[0];

  
// SQL Query to insert data into DataBase
$query = "INSERT INTO pincode(Pincode) VALUES('$col1')";
$s     = mysql_query($query);
 }
    fclose($handle);
}

}

?>

<form id="pincodeList" name="pincodeList" method="post" enctype="multipart/form-data">
               <div class="row">
               <div class="co-md-3 col-sm-6">
<input  type="file" name="Csv" >
                </div>
                <div class="co-md-3 col-sm-6">
<input class="btn btn-success" type="submit" name="submit" value="Upload Csv"/>
                </div>
                </div>
</form>

File or Image Upload Validation using Jquery Validation

File or Image Upload Validation using Jquery Validation Example

$("#form1").validate({

        rules: {
        
categoryBanner:{

filesize:1048576
},
        },
messages: { categoryBanner: "File must be JPG, GIF or PNG, less than 1MB" },


        highlight: function(element) {
            $(element).css({
                "background-color": "rgba(60, 141, 188, 0.52)",
                "border-color": "red"
            });
        },
        unhighlight: function(element) {
            $(element).css({
                "background-color": "",
                "border-color": ""
            });
        }

    });

$.validator.addMethod('filesize', function(value, element, param) {
    // param = size (in bytes)
    // element = element to validate (<input>)
    // value = value of the element (file name)
    return this.optional(element) || (element.files[0].size <= param)
});

<input type="file" name="categoryBanner" />
<input type="submit" name="submit"/>

Wednesday 20 January 2016

Upload Multiple-image Using Webservice in PHP



Hello
Upload Multiple-image Using Webservice in PHP

<?php



 
  if(isset($_POST['submit'])){
 
 
for($i=0; $i<count($_FILES['upload']['name']); $i++) {

/** valiation  only 1 Mb File Upload **/
if($_FILES['upload']['size'][$i] > 1048576){
$notice_image = '<div class="alert alert-info fade in">
    <a title="close" aria-label="close" data-dismiss="alert" class="close" href="#">×</a>
    <strong>Info!</strong> Image Size Must Be Less Than 1 Mb. Your Image is "'.$_FILES['upload']['name'][$i].'"
</div>';

}else{

$tmpFilePath =$_FILES['upload']['tmp_name'][$i];


//Make sure we have a filepath
if ($tmpFilePath != ""){
//Setup our new file path
$newFilePath = "ProductImg/";

if ( ! is_dir($newFilePath)) {

mkdir($newFilePath);


$picture =uniqid()."_".$_FILES['upload']['name'][$i];
$mypath = "ProductImg/".$picture;
//Upload the file into the temp dir
// if(move_uploaded_file($tmpFilePath, $mypath)) {
if(!file_exists($mypath)){
//move_uploaded_file($tmpFilePath, $mypath);
/** remove Comment when not use webservice*/

 
 
if(!empty($picture))
  {

 
$data = base64_decode($_FILES['upload']['name'][$i]);
$file = fopen($mypath, "w");
fwrite($file,$data);
fclose($file);
  }


}

}


}
}

}
?>

<form method="post" enctype="multipart/form-data">
<?php echo $notice_image; ?>
<input type="file" name="upload[]" multiple="multiple" >
<input type="submit" name="submit" value="save">

</form>