Empty WordPress custom post Data from MySql database table

Sometime while working on huge WordPress site, we may need to remove the old custom post data. Today we will discuss on how we can perform this action. For this we need to have phpmyadmin access,

then in SQL run the below code one by one as shown in figure above,

DELETE FROM wp_posts WHERE post_type='post_type';
DELETE FROM wp_postmeta WHERE post_id NOT IN (SELECT id FROM wp_posts);
DELETE FROM wp_term_relationships WHERE object_id NOT IN (SELECT id FROM wp_posts);

The first line deletes all posts with that post_type from wp_posts.

The second then removes any post metadata from wp_postmeta that is no longer tied to a post.

The third line removes and tags or categories from wp_term_relationships that were tied to that post type. This line should be omitted if you intend to create more posts of the given post_type in the future.

Source : Stackoverflow

Add .html to the URL of WordPress Pages

There may be requirement to change the wordpress url. The permalinks options of wordpress maynot be sometime sufficient as per client specification. To get .html the post can be done by changing permalinks in admin , but adding .html extension in the page url is not done by it. For that just add the below lines in functions.php of your theme

add_action('init', 'html_page_permalink', -1);
register_activation_hook(__FILE__, 'active');
register_deactivation_hook(__FILE__, 'deactive');
function html_page_permalink() {
	global $wp_rewrite;
	if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){
		$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
add_filter('user_trailingslashit', 'no_page_slash',66,2);
function no_page_slash($string, $type){
	global $wp_rewrite;
	if ($wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes==true && $type == 'page'){
		return untrailingslashit($string);
		return $string;
function active() {
	global $wp_rewrite;
	if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){
		$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
function deactive() {
	global $wp_rewrite;
	$wp_rewrite->page_structure = str_replace(".html","",$wp_rewrite->page_structure);

If you arenot intrested to do so then you can install this plugin from https://wordpress.org/plugins/html-on-pages/
Above code are also taken from the that plugin

If you want to get .php then then just change .html to .php on above code.

WordPress Permalinks on Windows IIS

Normally we host the wordpress site in linux hosting and everythings works fine with permalinks. But sometime server may be different , let say for the Windows IIS server the permalinks may not works hence resulting the URL that isnot SEO friendly. So to overcome this issue we need to create web.config in root directory and add the following code in the file.

<?xml version="1.0" encoding="UTF-8"?>
        <rule name="wordpress" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          <action type="Rewrite" url="index.php" />
Source : http://workfunc.com/how-to-setup-wordpress-permalinks-on-windows-iis/

WordPress Turn Off Auto Update for Single Plugin

Wordpress Turn Off Auto Update for Single Plugin
WordPress Turn Off Auto Update for Single Plugin

While working with plugins sometimes we need to change the default values and attributes of the plugin which may be lost as soon as the plugin creator add the update to wordpress.
For to disable the auto update or hiide update message from the admin we can add the follwing line in finction.php .

function filter_plugin_updates( $value ) {    
unset( $value->response['plugin-directory-name/plugin-file.php'] );    
return $value;
add_filter( 'site_transient_update_plugins', 'filter_plugin_updates' );

Here plugin-directory-name is the plugin folder name you want to disable and plugin-file.php is the main file of the plugin.

Source : http://wordpress.stackexchange.com/questions/25358/turn-off-auto-update-for-single-plugin

Create a pop-up WordPress email contact form 7

Contact form 7 can be used for different kinds of forms. Sometimes we may need to show the form in popup display. For to show the contact form in popup we can simply install Easy fancybox  and Contact Form 7 from wordpress plugin directoy and simple configure as below,
Firstly create contact form as you required and place contact form shortcode as below

<a href="#contact_form_pop" class="fancybox">Contact Us</a>

<div style="display:none" class="fancybox-hidden">
    <div id="contact_form_pop">
        [contact-form-7 404 "Not Found"]

For further detail you may visit to url below,

Source : http://geektastical.com/2011/05/how-to-create-a-pop-up-wordpress-email-contact-form/

Customize WordPress login logo without a plugin

Sometime wordpress developer need to change the wordpress logo in admin login screen while creating the site for the client. For that we can simply include the code below and deploy it without using any plugin. Simply copy and paste the code below in the function.php of your theme folder.

function my_custom_login_logo() {
    echo '<style type="text/css">
        h1 a { background-image:url('.get_bloginfo('template_directory').'/images/custom-login-logo.gif) !important; }

add_action('login_head', 'my_custom_login_logo');

The image that need to changed should be placed in the images folder of the theme.

Source: http://www.wprecipes.com/customize-wordpress-login-logo-without-a-plugin

Category Specific Single Post Templates

Sometimes we may required different category related single post template , i get the following things .
First put the code in function.php

// set up category specific single.php templates
add_filter('single_template', create_function('$t', 'foreach( (array) get_the_category() as $cat ) { if ( file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php") ) return TEMPLATEPATH . "/single-{$cat->slug}.php"; } return $t;' ));

Then create file as single-categoryname.php. Now the custom template will load while loading the page related to the categoryname.

WordPress : Displaying categories and subcategories “tree like”

Suppose you want to show a category / subcategory “tree like” list on a WordPress page that gets the posts from a certain “main” category.
The following code, probably will be useful.

//# first of all, you need to get the category array,
// and I did it, putting the line bellow inside the loop
$category = get_the_category(get_the_ID());

// once you have the category array, the rest of the code will work wherever you want on the page

//# getting the main category of the page

//# now letz get the children categories of the main category
$categories = get_categories('child_of='.intval($catid));

foreach ($categories as $category) {
//# check if it is a real parent category with subcategories
if ($category->parent ==$catid):
echo '<span><a href="">'.$category->cat_name.'</a></span>';
//# here we go, getting the subcategories
$subcategories= get_categories('child_of='.intval($category->cat_ID));
foreach ($subcategories as $subcategory) {
echo '<span style="padding-left:12px">';
echo '<a href="">'.$subcategory->cat_name.'</a></span>';


Displaying categories and subcategories “tree like” list on WordPress


WordPress Fatal error: Allowed memory size of 33554432 bytes exhausted

The problem:
Receive “Fatal error: Allowed memory size of 33554432 bytes exhausted” when try to upload an image with medium file size. To solve this error, try to increase the memory allocated to PHP. You can set the limit to 32MB, 64MB, 128MB or 256MB. It depends on your host.

Solution 1: Edit PHP.ini

If you’re still allowed to edit your PHP.inifile, update your memory_limit in PHP.ini by modifying the below line
memory_limit = 64M ; Maximum amount of memory a script may consume (64MB)
If the line is showing 64M in default, try 128M.

Solution 2: Edit .htaccess file

Add the script below to your .htaccess file.
php_value memory_limit 64M

Solution 3: Edit wp-config.php file

Add the script below to your wp-config.php file
Increasing memory allocated to PHP
define('WP_MEMORY_LIMIT', '64M');

Solution 4: Create a PHP.ini file to wp-admin folder
  1. Open Notepad.
  2. Insert the following code into Notepad.
    memory_limit = 64M ;
  3. Save as “PHP.ini”.
  4. Upload this file to “wp-admin” directory.
Source : http://www.hongkiat.com/blog/common-wordpress-errors-with-solutions/

Warning: Cannot modify header information – headers already sent by

Most of the time we donot actually care about leaving the blanks spaces before and after the “php” tag which results on “Warning: Cannot modify header information – headers already sent by (output started at /path/blog/somefile.php:4)“” .

The above problem could be solved by removing the blank spaces before “<?php” tag and after “?>” tag. and make sure the last characters are ?>, placed at the last line with no space in between.