WordPress curl post ajax request

Suppose you want to make a CURL POST to a WordPress function that accepts AJAX calls.
Below code makes a PHP CURL POST request to a wordpress AJAX function, “ajaxTester”:

Now you can receive the CURL POST parameters in your wordpress function and send a response:

Note: An example of running an AJAX request via CURL in WordPress, from Command Line:

You can observe the output for more info.

FacebookTwitterGoogle+LinkedInEmailShare

Use where clause at the end in joins

The result of the below 2 queries are different:

SELECT u.user_name FROM user u left join sales_people sp on u.id=sp.user_id where sp.profit=” and u.user_name like ‘%test%’ GROUP BY u.id

SELECT u.user_name FROM user u left join sales_people sp on u.id=sp.user_id and sp.profit=” where u.user_name like ‘%test%’ GROUP BY u.id

In the first query, we have the sequence: join, on, where, and
In the second query, we have the sequence: join, on, and, where

It is always recommended to use the second method of forming join queries, putting where clause at the last.
This way, we will get correct results.

FacebookTwitterGoogle+LinkedInEmailShare

Use in clause at the end in sub queries

The query (0.0020 sec):

SELECT u.user_name FROM user u where u.user_name like ‘%test%’ and u.id in (select user_id from user_role) GROUP BY u.id

is faster than the below query (0.0060 sec):

SELECT u.user_name FROM user u where u.id in (select user_id from user_role) and u.user_name like ‘%test%’ GROUP BY u.id

Reason could be due to the filtration of users by username, before doing the in() check.
So better put ‘in’ condition at the last.

FacebookTwitterGoogle+LinkedInEmailShare

wordpress update url database

Did you ever wished to change the URL for your wordpress site, or you have copied all files and database of a wordpress site to another site, and you wanted to change the URLs for the new one?

Below are the steps to be followed, to update the url settings of a wordpress site.

Step 1: Run the below queries in the database, to replace all the old URLs with new URLs:

Step 2 (Optional): Edit wp-config.php file to add the below lines to it, defining the new URL:

Done!

FacebookTwitterGoogle+LinkedInEmailShare

overlay div css example

The below example implements a div overlay on another div, by calculating the position, width and height of the first div, with jquery.

Here is a Demo.

FacebookTwitterGoogle+LinkedInEmailShare

jsonp ajax call jquery

Normally jquery ajax does not permit making cross domain requests.
So if we are on site A, we cannot make an ajax call to a page on site B, to get a json response.

This limitation is solved by using jsonp call of jquery ajax, specifying a callback function at both the sides.

Below is an example of making a jsonp call using jquery ajax.

The server side code must send ajax json response as a callback function, like:

Then the caller ajax code should implement the callback function:

Then loop over the json response, in the callback function:

Reference: Here

FacebookTwitterGoogle+LinkedInEmailShare

Online Web Tutorials