February 16 2016

WordPress Header error wp-includes/pluggable.php

Tagged Under : ,

Wordpress
When using wp_redirect() you will facing Header error “PHP Warning: Cannot modify header information – headers already sent by …… wp-includes/pluggable.php on line 1228”

To solve this problem you need to change the PHP.ini value. In PHP.ini find

February 16 2016

WordPress Ajax Example

Tagged Under : , ,

Wordpress
Below is the basic example of how to use AJAX in WordPress. It show you how to using javascript pass the variable to PHP function and then return back to javascript.

Javascript
var ajaxurl = '<?php echo admin_url() ?>admin-ajax.php';
jQuery(document).ready(function () {
	jQuery.ajax({
		url: ajaxurl,
		data: {
			//This action must same with the PHP function name
			"action": "ajax_request",
			"params": "wordpress ajax"
		},
		success:function(data) {
			//This is the result return from PHP function
			console.log(data);
		},
		error: function(errorThrown){
			//This is the error return
			console.log(errorThrown);
		}
	});
});

April 08 2014

WordPress how to create or build a new simple plugin

Tagged Under :

Wordpress
To create a plugin is a single PHP file, but common practice put the files within a directory. To begin, create a folder and naming it as your plugin name. Then, create a main PHP file and naming the file with the name of your plugin:
my-first-plugin << Folder name
- my-first-plugin.php << main PHP file name

Now we need define the plugin so the WordPress will recognize it and allow it to be installed, removed, and activated. Open the main PHP file (my-first-plugin.php), and then add the following code to the top of the file:

December 25 2013

A better way to get item url in WordPress

Tagged Under :

Wordpress
When linking to posts or images from your posts, there is a more versatile means of doing so. Imagine that you change themes or move to another domain. You need to go through entire posts to search and replace every link.

Maybe you will think linking the posts or images like below example:
<a href="../contact/" >Contact Us</a>
But it was bad way.

This is worse as well:
<a href="http://chevronscode.com/contact/" >Contact Us</a>

December 09 2013

WordPress easy way to display the number of search results

Tagged Under :

Workpress
In prepping the new site design for my client, I need to show the total number of search results on my search page.

From the wordpress Forum I found 1 of the solution. Like the below example code.
$mySearch =& new WP_Query("s=$s & showposts=-1");
$num = $mySearch->post_count;
echo $num. "results";
But unfortunately, sometimes it still gave me the wrong count.