How to Use Shortcodes in WordPress Text Widgets

Just add the following code in the functions.php file

add_filter('widget_text', 'do_shortcode');

How to change the Site URL and Home URL on a WordPress Site

When do you need to change the site URL and home URL in wordpress

1. When you move your site from your PC to online or simply when you move your project from one location to another.

Solution:

Simply , Add the following lines in wp-config.php to update site URL and Home URL as

1. wp-config.php

define('siteurl','http://example.com');
define('home','http://example.com');

OR
2.Add the following lines in functions.php

update_option('siteurl','http://example.com');
update_option('home','http://example.com');

OR
3. Use the following sql query to update the site url and home url as

UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldsite.com', 'http://www.newsite.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldsite.com','http://www.newsite.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldsite.com', 'http://www.newsite.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://www.oldsite.com', 'http://www.newsite.com');

How to find the lengtth of array checkbox checked using javascript

var inputTags = document.getElementsByTagName(‘input’);
var checkboxCount = 0;
length = inputTags.length;

for (var i=0;  i<length; i++) {
if (inputTags[i].type == ‘checkbox’ &&  inputTags[i].checked) {
checkboxCount++;
}
}

if(checkboxCount<=0){
alert(‘Some messageg’);

return false;
}

Changing the NLS Character Set in Oracle

Procedure to Change the Character set in oracle to support the local characters like unicode.

SQL> SHUTDOWN IMMEDIATE;
SQL> CONNECT SYS/password AS SYSDBA;
SQL> STARTUP MOUNT;
SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;
SQL> ALTER DATABASE OPEN;
SQL> ALTER DATABASE CHARACTER SET INTERNAL_USE AL32UTF8;
SQL> SHUTDOWN;
SQL> STARTUP;
SQL> QUIT;

How to get the top most parent ( parent’s parent ) Recursively in php , when to use Recursive Function

My table Structure:

id parent_id menu name
1 0 Home
2 0 Gallery
3 0 Message
4 3 From Principal
5 3 From Guardian
6 2 Events
7 2 Students
8 6 Picnic
9 6 Sports

Major Requirement:

Input : 9 (Sports->Events->Gallery Bottom Up Parent Wise)

output: 2 (Gallery->Events->Sports Top Down )

Our Requirement is to make the function that will return us the top most parent of any menu item. Lets say i need to find the parent of Sports (id=9) menu which is simple i.e. the menu name with id 6 i.e. Events

Simply we will write the simple query: select menu_name from table_name where id=6

But it is not as simple as we have thought to find the top most parent of any menu . Because sometime we don’t know the depth i.e level at which the top most parent  is.

Here we actually don’t know the depth or level of top most parent . If you don’t know the level then use the recursive function it will save your cost of programming . Recursive function will solve your problem with magic:

Here is the Code :

 function get_most_root_of_any_id($id=NULL){

        if($id==NULL){
            return false;
        }

        $this->CI->db->select("parent_id");
        $this->CI->db->where("id",$id);
        $result = $this->CI->db->get("table_name");

        if($result->num_rows()==0){
            return false;
        }

      $record =  $result->first_row();

      if($record->parent_id==0){
            return $id;
      }else{
        return $this->get_most_root_of_any_id($record->parent_id);
      } 

    }

This Example is made on the basis of Codeigniter , So please modify as per your need . More on RECURSION Enjoy…