Get list of all WooCommerce categories.

$orderby = 'name';
$order = 'asc';
$hide_empty = false ;
$cat_args = array(
    'orderby'    => $orderby,
    'order'      => $order,
    'hide_empty' => $hide_empty,
);

$product_categories = get_terms( 'product_cat', $cat_args );

if( !empty($product_categories) ){
	echo '<ul>';
	foreach ($product_categories as $key => $category) {
		echo '<li>';
		echo '<a href="'.get_term_link($category).'" >';
		echo $category->name;
		echo '</a>';
		echo '<li>';
	}
	echo '</ul>';
}

Remove version parameters from WordPress javascript and css urls

In WordPress version number are append to javascript and css url. you can see these in browser by press ‘Ctrl+U’ or right click on web page then click on ‘View page source’. Continue reading “Remove version parameters from WordPress javascript and css urls”

Recursive category tree in php and mysql

Sometime you face problem in php to manipulate hierarchical data. This code will show you that how to display category tree in php. Here Mysql database used to store data. I have used here recursive method which search data in n Level . for example level 1 , level 2 , level 3 , level N…. as on. This simple code will work for multiple level as par your requirement. For example level 0 have ‘year’ category and its subcategory has ‘Jan’ ,’Feb’ as on. Continue reading “Recursive category tree in php and mysql”

Applying the Category to Attachments in WordPress

You can assign category to media in wordpress using following php code.

function ptt_add_categories_to_attachments() {
	register_taxonomy_for_object_type( 'category', 'attachment' );
}
add_action( 'init' , 'ptt_add_categories_to_attachments' );

Continue reading “Applying the Category to Attachments in WordPress”