Skip to main content

Posts

How to Create a jQuery Autocomplete in Wordpress

How to Create a jquery-ui Autocomplete in wordpress. Autocomplete provides suggestions while you type into the text field. In Wordpress we fetch dynamically matched pattern. Include javascript and css files in header. Create action inside functions.php or inside plugin code. add_action('wp_head', 'custom_register_scripts'); function custom_register_scripts(){ wp_register_style( 'techsudhir_jquery_ui_css', plugin_dir_url(__FILE__) . 'css/jquery-ui.css', false,'1.0.0' ); wp_enqueue_style( 'techsudhir_jquery_ui_css' ); wp_register_script('techsudhir_jquery_ui_js',plugin_dir_url(__FILE__) . 'js/jquery-ui.js',array('jquery'),'1.1', false); wp_enqueue_script('techsudhir_jquery_ui_js'); wp_localize_script( 'techsudhir_autocomplete', 'jqueryAutocomplete', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); wp_enqueue_script( 'techsudhir_...

Simple CRUD Example in Cakephp

Simple CRUD Operation in CakePHP 2.x This tutorial will explain about CRUD Operation in CakePHP. Here we will perform mysql Insert, Select, Update, Delete operation in cakePHP Framework. As we know CakePHP uses MVC design patterns. Here we will cover following points: 1. MySQL Database Table Used 2. We are using CakePHP Version 2.x 3. Create/Select/Update/Delete records. We have assume that you have already created you database table. Here is simple users table structure. CREATE TABLE `users` (   `id` bigint(20) UNSIGNED NOT NULL primary key AUTO_INCREMENT,   `firstname` varchar(128) NOT NULL,   `lastname` varchar(128) DEFAULT NULL,   `username` varchar(128) DEFAULT NULL,   `password` varchar(128) DEFAULT NULL,   `email` varchar(128) DEFAULT NULL,   `created` datetime DEFAULT NULL,   `modified` datetime DEFAULT NULL, ) Create action inside Users controller. Controller: app/Controller/UsersController.php Create add functi...

How to use Ajax in WORDPRESS

How AJAX Works In WordPress What's AJAX? AJAX stands for Asynchronous JavaScript And XML . It is the use of the XMLHttpRequest object to communicate with servers, which means it can communicate with the server, exchange data, and update the page without having to refresh the page. Step1: Define the Ajax URL. var ajaxurl = '<?php echo admin_url( 'admin-ajax.php' );?>'; Step2: Define its action and perform with using POST method var emailAddress = jQuery('#uemail').val(); var searchData = { action: 'get_registered_email', email_address:emailAddress, } Step 3: Perform ajax request jQuery.ajax({ url: ajaxurl, type: "POST", data: searchData, success: function(data){   jQuery("div#divLoading").removeClass('show');   jQuery('#memberResult').html(data);   //alert(data); }, error: function(errorThrown){ alert(errorThrown); } }); Step 4: Use Wordpress 2 ajax hooks...

How to create STAR PATTERN in PHP

STAR Pattern Printing using PHP for loop Pattern: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Code: for($i=0; $i<5; $i++) { for($j=0; $j<5; $j++) { print_r(" * "); } print_r("<br/>"); } Pattern: * * * * * * * * * * * * * * * Code: for($i=0; $i<5; $i++) { for($j=0; $j<=$i; $j++) { print_r(" * "); } print_r("<br/>"); } Pattern:              *          * *        * * *     * * * *  * * * * * Code: for($i=0; $i<5; $i++) { for($j=5; $j>=$i; $j--) { print_r("&nbsp; ");  } for($k=0; $k<=$i; $k++) { print_r("*"); } print_r("<br/>"); } Pattern: * * * * *    * * * *       * * *          * *             * Code: $temp = 1; for($i=5; $i>=1; $i--) { for($k=$temp; $...

6 guaranteed steps how to create CRON JOB FUNTION in wordpress

Create Cron Job function in Wordpress plugin Step 1: Register function on plugin activate  register_activation_hook(__FILE__, 'activate_one'); Step 2: add_filter function for interval //Filter for Adding multiple intervals add_filter( 'cron_schedules', 'intervals_schedule' ); // define interval function   function intervals_schedule($schedules) {   $schedules['everyminute'] = array(    'interval' => 60, // Every 1 minutes    'display'  => __( 'Every 1 minutes' )   );   return $schedules;  } Step 3: Activate hook function   //Schedule a first action if it's not already scheduled   function activate_one() {   if (!wp_next_scheduled('wpyog_cron_action')) {    wp_schedule_event( time(), 'everyminute', 'wpyog_cron_action');   }  } Step 4: Cron hook function   //Hook into that action that'll fire after 1 minutes   add_action('wpyog_cron_action', 'execute_...

Simple JavaScript Object and Class Examples

In JavaScript, most things are objects. An object is a collection of related data and/or functionality Namespace: Everything you create in JavaScript is by default global. In JavaScript namespace is Global object . How to create a namespace in JavaScript? Create one global object, and all variables, methods, and functions become properties of that object. Example:  // global namespace var MYAPP = MYAPP || {}; Explaination: Here we first checked whether MYAPP is already defined.If yes, then use the existing MYAPP global object, otherwise create an empty object called MYAPP How to create sub namespaces? // sub namespace MYAPP.event = {}; Class JavaScript is a prototype-based language and contains no class statement.JavaScript classes create simple objects and deal with inheritance. Example: var Person = function () {}; Explaination: Here we define a new class called Person with an empty constructor. Use the class keyword class Calculation {}; A class expr...

PHP Fresher Technical Interview Questions

PHP Fresher Technical Interview Questions Question : How to find out leap year? Answer:  A leap year is a calendar year containing one additional day. It has 366 days instead of the usual 365 days. function isLeapYear($year){   return ((0 == ($year % 4)) && (0 != ($year % 100)) || (0 == ($year % 400))); } var_dump(isLeapYear(2020)); Code Explanation: Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400. Question : How to find out Prime number? Answer:   Prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Function to check whether prime number or not function isPrimeNumber($num){ $flag = 0; for($i=2; $i<=$num/2; ++$i)     {         // condition for nonprime number         if($num%$i==0)   ...