28 March 2020

How to Get Category name from Post ID in wordpress?

Get Category name from Post ID

$category_detail=get_the_category('4');//$post->ID
foreach($category_detail as $cd){
echo $cd->cat_name;
}

21 March 2020

if jQuery contain and match value then replace with another value on load in jQuery?

if jQuery contain and match value then replace with another value on load in jQuery.




$(window).on("load", readyFn);
function readyFn() {
   $('#chart-container text').each(function() {
var ourText = $(this).text().toLowerCase(); // convert text to Lowercase
if(ourText.match('75%')) {
$(this).html( "h" );
}     
});

}

How to fix If value is infinity, empty and NaN in jQuery?

 fix If value is infinity, empty and NaN in jQuery

if (theResult == Infinity || theResult == "" || theResult == NaN) {
    theResult == 0;
}
$("#theResult").val(theResult);

19 March 2020

How to get Selected Option Text of HTML SELECT using jQuery?

Get Selected Option Text of HTML SELECT using jQuery


<select id="mySelect">
    <option value="1">hello</option>
    <option value="2">bro</option>
</select>
<input type="button" id="test" value = "test" />
<script type="text/javascript">
    $("#test").live("click"function () {
        
        var selectedText = $("#mySelect option:selected").html();
        alert(selectedText);
    });
</script>

18 March 2020

How to get full detail of any mobile number in cordova?

Get full detail of any mobile number in cordova.


document.addEventListener("deviceready", hello, false);
function hello(){
navigator.contacts.pickContact(function(contact){
 console.log('The following contact has been selected:' + JSON.stringify(contact));
 
document.getElementById("number").innerHTML = 'The following contact has been selected:' + JSON.stringify(contact);
    },function(err){
        console.log('Error: ' + err);
    });
}

How to get all contacts and count contact numbers from mobile in cordova?

Get  all contacts and count contact numbers from mobile in cordova.


document.addEventListener("deviceready", jaspreet, false);
function jaspreet() {
   //
   //
   // after deviceready
   //
   //
   navigator.contactsPhoneNumbers.list(function(contacts) {
      console.log(contacts.length + ' contacts found');
  alert(contacts.length);
      for(var i = 0; i < contacts.length; i++) {
         console.log(contacts[i].id + " - " + contacts[i].displayName);
         for(var j = 0; j < contacts[i].phoneNumbers.length; j++) {
            var phone = contacts[i].phoneNumbers[j];
            console.log("===> " + phone.type + "  " + phone.number + " (" + phone.normalizedNumber+ ")");
document.getElementById("names").innerHTML +=phone.type + "  " + phone.number;
         }
      }
   }, function(error) {
      console.error(error);
   });
   


}

How to get unique mobile ID (device Id) from mobile in cordova?

Get unique mobile ID (device Id)  from mobile in cordova.

  <script type="text/javascript" charset="utf-8">

    // Wait for Cordova to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);


    // Cordova is ready
    //
    function onDeviceReady() {


        var element = document.getElementById('deviceProperties');

        element.innerHTML = 'Device Name: '     + device.name     + '<br />' +
                            'Device Cordova: '  + device.cordova  + '<br />' +
                            'Device Platform: ' + device.platform + '<br />' +
                            'Device UUID: '     + device.uuid     + '<br />' +
                            'device model: '     + device.model     + '<br />' +
                            'device manufacturer: '     + device.manufacturer     + '<br />' +
                            'device isVirtual: '     + device.isVirtual    + '<br />' +
                            'device serial: '     + device.serial    + '<br />' +
                            'Device Version: '  + device.version  + '<br />';
    }

</script>

17 March 2020

How to get values and parameters from url with jquery in cordova with example?

Get values and parameters from url with jquery in cordova with example

Paste in Function.php file


 function check_login(){
 
 if(function_exists('date_default_timezone_set')) {
    date_default_timezone_set("Asia/Kolkata");
}

// then use the date functions, not the other way around
$date = date("d/m/Y");
$date1 =  date("H:i a");
$phone = $_POST['phone'];
$password = $_POST['pass'];

global $wpdb;
$table_name = $wpdb->prefix ."customer";
 $result = $wpdb->get_results ( "SELECT * FROM $table_name WHERE phone='$phone' AND password='$password'" );
$count_users = count($result);
foreach($result as $print_result){
}

 if($count_users>0){
 
 
//echo '<script>window.location.href="dashboard.html";</script>'; 
echo $print_result->ID;
 
}
else{
 
echo 'null'; 
 
}
 
  die();
 }

 add_action('wp_ajax_nopriv_check_login','check_login');
 add_action('wp_ajax_check_login','check_login');
 
 

Paste in Login.html file



$('.login').click(function(e) {
e.preventDefault();
var phone = $(".l_phone").val();
var pass = $(".l_password").val();
var ajax = "http://wpcodekit.com/wp-admin/admin-ajax.php";
 
  if(phone==''){
alert('All field are required');
return false;
 
}
  if(pass==''){
alert('All field are required');
return false;
 
}

//alert(pass);
 

  var data = {
'action' : "check_login",
'phone' :phone,
'pass' : pass
}
$.post(ajax,data,function(response){
var user_id = response; 
window.location.href="dashboard.html?ID="+user_id+"";
//alert(user_id);
console.log(user_id);
});


});

Paste in dashboard.html file

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

var first = getUrlVars()["ID"];
alert(first);

How to Get URL parameters & values from url in jQuery?

function

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}


Url


http://www.example.com/jassi.html?me=myValue&name2=SomeOtherValue

OR

http://www.example.com/?me=myValue&name2=SomeOtherValue


Usage


var first = getUrlVars()["me"];

// To get the second parameter
var second = getUrlVars()["name2"];

13 March 2020

How to fetch data from database in cordova app with ajax in wordpress?

fetch data from database in cordova app with ajax in wordpress.


Paste in funtion.php file.



 function fetch_cordova_message(){

if(function_exists('date_default_timezone_set')) {
date_default_timezone_set("Asia/Kolkata");
}

// then use the date functions, not the other way around
$date = date("d/m/Y");
$date1 =  date("H:i a");

global $wpdb;
$table_name = $wpdb->prefix ."customer";
$result = $wpdb->get_results ( "SELECT * FROM $table_name Order by ID desc" );
foreach ( $result as $print ) 
{
            echo'<div class="list_row"><div class="per_name">'.$print->person .'</div><div class="full_view">></div></div>';
        }

die();
 }

 add_action('wp_ajax_nopriv_fetch_cordova_message','fetch_cordova_message');
 add_action('wp_ajax_fetch_cordova_message','fetch_cordova_message');

function add_cors_http_header(){
    header("Access-Control-Allow-Origin: *");
}
add_action('init','add_cors_http_header');

add_filter( 'wp_headers', 'send_cors_headers', 11, 1 );
function send_cors_headers( $headers ) {
    $headers['Access-Control-Allow-Origin'] = $_SERVER[ 'HTTP_ORIGIN' ];
    return $headers;
}


Paste in main file.

jQuery(document).ready(function($){

function fetch_customer_list(){
var ajax = "http://wpcodekit.com/wp-admin/admin-ajax.php";
  var data = {
'action' : "fetch_cordova_message"
}
$.post(ajax,data,function(response){
//$("#response").html(response);
//console.log(response);
$('.customer_list').html(response);
});

}
fetch_customer_list();
});

How to insert data in database with ajax in cordova?

Insert data in database with ajax in cordova.

Paste in function.php file

 function insert_cordova_message(){

 if(function_exists('date_default_timezone_set')) {
    date_default_timezone_set("Asia/Kolkata");
}

// then use the date functions, not the other way around
$date = date("d/m/Y");
$date1 =  date("H:i a");


$person = $_POST['person'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$password = $_POST['pass'];

global $wpdb;
$table_name = $wpdb->prefix ."customer";
$wpdb->insert($table_name, array('person' => $person, 'email' => $email,'phone' => $phone, 'password' => $password,'registered_date' => $date) );



  die();
 }

 add_action('wp_ajax_nopriv_insert_cordova_message','insert_cordova_message');
 add_action('wp_ajax_insert_cordova_message','insert_cordova_message');


function add_cors_http_header(){
    header("Access-Control-Allow-Origin: *");
}
add_action('init','add_cors_http_header');

add_filter( 'wp_headers', 'send_cors_headers', 11, 1 );
function send_cors_headers( $headers ) {
    $headers['Access-Control-Allow-Origin'] = $_SERVER[ 'HTTP_ORIGIN' ];
    return $headers;
}


Paste in main file


$('.registration').click(function(e) {
e.preventDefault();

var person = $(".person").val();
var email = $(".email").val();
var phone = $(".phone").val();
var pass = $(".password").val();
var ajax = "http://wpcodekit.com/wp-admin/admin-ajax.php";

if(person==''){
alert('All field are required');
return false;

}
if(email==''){
alert('All field are required');
return false;

}
  if(phone==''){
alert('All field are required');
return false;

}
  if(pass==''){
alert('All field are required');
return false;

}

//alert(pass);


  var data = {
'action' : "insert_cordova_message",
'person': person,
'email' : email,
'phone' :phone,
'pass' : pass
}


$.post(ajax,data,function(response){

location.reload(true);
});


});

How to create session in cordova app with jquery (ajax) in wordpress?

Create session in cordova app with jquery in wordpress.

Paste in function.php file.


function check_login(){

 if(function_exists('date_default_timezone_set')) {
    date_default_timezone_set("Asia/Kolkata");
}

// then use the date functions, not the other way around
$date = date("d/m/Y");
$date1 =  date("H:i a");

$phone = $_POST['phone'];
$password = $_POST['pass'];

global $wpdb;
$table_name = $wpdb->prefix ."customer";
 $result = $wpdb->get_results ( "SELECT * FROM $table_name WHERE phone='$phone' AND password='$password'" );
$count_users = count($result);
foreach($result as $print_result){
}

 if($count_users>0){
 
 
//echo '<script>window.location.href="dashboard.html";</script>'; 
echo $print_result->ID;
 
}
else{
 
echo 'null'; 
 
}


  die();
 }

 add_action('wp_ajax_nopriv_check_login','check_login');
 add_action('wp_ajax_check_login','check_login');



Paste in main file.



jQuery(document).ready(function($){
 
var user_id = window.localStorage.getItem("ID");
//alert(user_id);
  if(user_id!==null){
window.location.href="dashboard.html";
}
$('.login').click(function(e) {
e.preventDefault();
var phone = $(".l_phone").val();
var pass = $(".l_password").val();
var ajax = "http://wpcodekit.com/wp-admin/admin-ajax.php";
 
 

  var data = {
'action' : "check_login",
'phone' :phone,
'pass' : pass
}
$.post(ajax,data,function(response){
var user_id = response; 
//alert(user_id);
console.log(user_id);
  if(user_id!=='null'){
window.localStorage.setItem("ID", response);
var ID = window.localStorage.getItem("ID");
window.location.href="dashboard.html";
}
});
});
});


dashboard in main file.



jQuery(document).ready(function($){

var user_id = window.localStorage.getItem("ID");
if(user_id==null)
{
window.location.href="index.html";
});

dashboard (OR any file) in main file.

jQuery(document).ready(function($){

     $('.logout').click(function() {
var jassi = window.localStorage.removeItem("ID");
window.localStorage.removeItem("ID");
window.localStorage.clear();
  //alert(jassi);
         var user_id = window.localStorage.getItem("ID");
 //alert(user_id);
 window.location.href="index.html";
});
 
});  

How to get multiple values from ajax in wordpress?

Get multiple values from ajax in wordpress.





Paste this code in main file. 


function single_user_data(){
var ajax = "http://wpcodekit.com/wp-admin/admin-ajax.php";
   var data = {
'action' : "get_single_use",
'ID': user_id
}
$.post(ajax,data,function(response){
var result = $.parseJSON(response)
$(".first").html(result[0]);
$(".second").html(result[1]);
console.log(response);
});
}
single_user_data();




Paste this code in function.php file.



 function get_single_use(){
 
  $user_id = $_POST['ID'];
  if(function_exists('date_default_timezone_set')) {
date_default_timezone_set("Asia/Kolkata");
}

// then use the date functions, not the other way around
$date = date("d/m/Y");
$date1 =  date("H:i a");

global $wpdb;
$table_name = $wpdb->prefix ."customer";
$result = $wpdb->get_results ( "SELECT * FROM $table_name where ID='$user_id' Order by ID desc" );
foreach ( $result as $print )  
{
           
        }
  $person = $print->person;
  $phone = $print->phone;
echo json_encode(array($person,$phone));
die();
 }

 add_action('wp_ajax_nopriv_get_single_use','get_single_use');
 add_action('wp_ajax_get_single_use','get_single_use');

06 March 2020

How to upload file into wordpress child theme folder in wordpress ( file upload) ?


upload file into wordpress child theme folder in wordpress ( file upload)


if(isset($_POST["submit_p_img"])){


$filename = $_FILES["p_img"]["name"];
$tempname = $_FILES["p_img"]["tmp_name"];
echo $folder =  $_SERVER["DOCUMENT_ROOT"]."/messanger/wp-content/themes/twentytwenty-child/pimg/".$filename;
move_uploaded_file($tempname,$folder);
}

02 March 2020

How to fetch data by limit in php (How to use sqi in sql in php) (two mysqls)?

 fetch data by limit in php (How to use sqi in sql in php) (two mysqls)


$msg_content = $_POST['msg_content'];
$own_id = $_POST['own_id'];
$user_id = $_POST['user_id'];
global $wpdb;
$table_name13 = $wpdb->prefix . "user_chats";
$results = $wpdb->get_results("select  from (select  from $table_name13 where (sender_id ='$own_id' AND receiver_id='$user_id') OR (sender_id ='$user_id' AND receiver_id='$own_id') order by ID DESC LIMIT 10) $table_name13 order by ID");
$total = count($results);

foreach($results as $result){
$sender_id = $result->sender_id;
$receiver_id = $result->receiver_id;
if($sender_id == $own_id AND $receiver_id == $user_id){
echo "
<div class='right_side_chat' style='text-align:right;background:blue; margin-left:30%; margin-bottom:4px; padding:5px 10px;'>
<span>$result->ID</span>
</div>
";
}
else{
echo "
<div class='right_side_chat' style='background:red; text-align:left;margin-right:30%;margin-bottom:4px;padding:5px 10px;'>
<span>$result->ID</span>
</div>
";
}




}

How to add re-captcha v3 on all Elementor forms using coding?

 Add re-captcha v3 on all Elementor forms using coding add_action('wp_footer',function(){     ?> <script src="https://www...