WordPress Database Queries

/**
 * insert
 */
$wpdb->insert( $wpdb->posts, array( 'post_title' => $mytitle ) );

$wpdb->insert( $wpdb->options, array(
            'option_name',
            'new_option_key',
            'option_value' => 'New Option Value',
            'autoload' => 'yes' )
            );

/**
 * update
 */
$wpdb->update( $wpdb->posts, array( 'post_title' => $mytitle ),
            array( 'ID' => $myid )
            );

$wpdb->update( $wpdb->options,
            array( 'option_value' => 'New Option Value' ),
            array( 'option_name' => 'new_option_value' )
            );

/**
 * get_var
 */
$post_id = $wpdb->get_var(
            $wpdb->prepare( "SELECT post_id FROM
                    $wpdb->postmeta WHERE
                    post_id = %d AND
                    meta_key = 'enclosure' AND
                    meta_value LIKE (%s)", $post_ID, $url . '&' )
            );

$content = $wpdb->get_var(
            $wpdb->prepare("SELECT post_content FROM " .
                    "$wpdb->posts WHERE " .
                    "post_title = %s AND " .
                    "ID = %d", $title, $id )
        );

/**
 * query
 */
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" );

$wpdb->query( "UPDATE $wpdb->posts SET post_title = '$mytitle' WHERE ID = $myid" );

/**
 * query and escape
 */
$mytitle = $wpdb->escape( $mytitle );
$myid    = absint( $myid );
$wpdb->query( "UPDATE $wpdb->posts SET post_title = '$mytitle' WHERE ID = $myid" );

/**
 * get_results
 */
$type = $wpdb->get_results( "SELECT post_type FROM " .
                "$wpdb->posts WHERE ID=$id" );

Ajax in WordPress Plugin

If you needed to create an AJAX handler for an “my_ajax” request, you would create a hook like this:
add_action(‘wp_ajax_my_ajax’, ‘my_ajax’);

function my_ajax() {
       die("Hello World");
}

Using the above example, any time an AJAX request is sent to WordPress, and the request’s ‘action’ property is set to ‘my_ajax’, this hook will be automatically executed.
For example, the following code would execute the above hook.

jQuery.post(
    ajaxurl,
    {
        'action':'my_ajax',
        'data':{
            name: "Sang", 
            location: "India"
        }
    },
    function(response){
        alert('The server responded: ' + response);
    }
    );

Windows 7 Build 7601 not genuine

Go to Control Panel > Programs and Features and Click “View Installed Updates” on the upper left corner.

Then right click to “Uninstall” the patch then press “Yes” as shown below.

Windows Software Games Anti virus Computers and Technology   AuxiuS

Click Start Button and type “cmd” then important to run “CMD” as administrator.

1

On cmd type the following command “slmgr -rearm” and a msgbox will appear says that you have to restart your pc press ok then restart.

2

After restart,run CMD as administrator type the following command “slmgr -ato”,

press OK.

[if error occur ignore it].

3

Click Start button type “Windows Update” and run,

Click “Change Seetings” and set “Important Updates” to “Let me choose whether to download or Install them”

press Ok,

click “Check for Updates”.

If windows finds an important update,click on it to verify.

🙂

PHP – How to Set Up a Virtual Host on Localhost in Apache in Ubuntu

1. Make a copy of the default configuration file with a command similar to the following:

cp /etc/apache2/sites-available/default /etc/apache2/sites-available/newdomain

The new file “newdomain” is the name of your second site.

2.Update the file you created in Step 1, changing or adding the following lines:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost.com
    ServerName www.newdomain.com
    ServerAlias www.newdomain.com
    DocumentRoot /var/www/newdomain
    # Other directives here
 <Directory>
     Options FollowSymLinks
     AllowOverride None
 </Directory>
 <Directory /var/www/newdomain>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
 </Directory>
</VirtualHost>

Save the file and exit.

cp  /etc/apache2/sites-available/newdomain  /etc/apache2/sites-enable/newdomain

ln -s /etc/apache2/sites-available/newdomain  /etc/apache2/sites-enable/newdomain

3. Create a new directory to house the web pages for your second domain:

mkdir /var/www/newdomain

This directory will hold the pages for your second web site.
4. Open up your hosts file:

etc/hosts
and at the end of file put this
127.0.0.1 www.newdomain.com

5.Activate your new domain with the following command:

a2ensite newdomain

Start (or restart) Apache with the following command:

/etc/init.d/apache2 reload

6. Build a web page named “index.html” and store it in the directory “newdomain” created in Step 4.

7. result: In Browser type http://www.newdomain.com in addressbar and see its works!.
Good Job!

Php – Integrate Viddy api

Fetch user’s vedio from viddy.

$api_key = "your api key";
$access_token = "access_token";

$url = "http://api.viddy.com/v1/users/me/media?access_token=" . $access_token . "&apikey=".$api_key;

$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl_handle);
curl_close($curl_handle);

print_r($response);

Mustache Template

Mustache can be used for HTML, it “logic-less” because there are no if statements, else clauses, or for loops. Instead there are only tags. Some tags are replaced with a value, some nothing, and others a series of values.

Template:

Hello {{name}}
From : {{company}}

Hash:
{
“name”: “Sang”,
“company”: “Xyz”
}

Output:

Hello Sang
From Xyz

Cakephp session timeout issue resolved

Session Time out resolved in cakephp 2.0 or above to follow this steps:

open app/config/core.php

replace this code

Configure::write(‘Session’, array(
‘defaults’ => ‘php’,
));

with the below code

Configure::write(‘Session’, array(
‘defaults’ => ‘php’,
‘cookieTimeout’ => 0,
‘cookie’ => ‘newNameSESSION’,
));

and maintain the security level
Configure::write(‘Security.level’, ‘medium’);

Create virtual host in WAMP Server

If you’re using WAMP for your local development, here’s how to setup virtual hosts.

1.Open C:\wamp\bin\apache\Apache2.2.11\conf\httpd.conf and   uncomment the virtual hosts include and save:

Include conf/extra/httpd-vhosts.conf

2. Open your windows host file, C:\WINDOWS\system32\drivers\etc\hosts , and add the name you want to use for your virtual host.

-> The hosts files has entries which maps IP Address to a name. By default the name “localhost” is mapped to 127.0.0.1 IP Address.

127.0.0.1 localhost

-> Now what we have to do is to simply add few more entries per client in this file. You may want to use your clients domain name as mapping key (e.g. sang.local)

127.0.0.1 client.local

3. Create a Client Site Folder:
Let’s create another one at “C:\wamp\client”

4. Serve Multiple Sites by Name:
WAMP configures Apache to serve a single site that usually lives in “C:\wamp\www”. Apache can handle multiple sites if we tell it where to look. To open your WAMP Server Apache configuration, left-click the WAMP Server icon and select “Apache -> httpd.conf”.

Search for a line like this:
Listen 80

Change it to this:
Listen *:80
5. At the end of httpd.conf, add this:
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot ‘C:\wamp\www’
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName client.local
DocumentRoot ‘C:\wamp\client’
</VirtualHost>

6. Restart Apache and Test :
Browse to http://client.local and you should see your new site.