How to fetch wordpress categories

How to get wordpress categories data

0 121

Latest Blog all know wordpress is a popular blogging platform, And there is a lots of inbuilt functions available in wordpress library to customize user experience, So in this sort tutorial we’ll know about fetching wordpress categories by some inbuilt function like get_categories(), wp_list_categories(), wp_dropdown_categories(). You can request output in two format in object array or string.

get_categories()

With this function you can fetch wordpress categories in object array format and customize it where you want.

Fetching categories in string format.

<?php get_categories(style=list&hide_empty=1); ?>

Fetching categories in object format.

You need to pass the categories options and can defile output types.

<?php  
    $options = array(
	'style'      => 'list',
	'hide_empty' => 1,
	);
    get_categories($options); 
?>

wp_list_categories()

With this function you’ll get the formatted list of your wordpress categories in html format.

Fetching categories in string format.

<?php wp_list_categories(style=list&hide_empty=1); ?>

>

Fetching categories in object format.

You need to pass the categories options and can defile output types.

<?php  
    $options = array(
	'style'      => 'list',
	'hide_empty' => 1,
	);
    wp_list_categories($options); 
?>

 

wp_dropdown_categories()

With this function you can directly fetch wordpress category in list box, This simple function retun wordpress categories in dropdown list box.

Fetching categories in string format.

<?php wp_dropdown_categories(style=list&hide_empty=1); ?>

Fetching categories in object format.

You need to pass the categories options and can defile output types.

<?php  
    $options = array(
	'style'      => 'list',
	'hide_empty' => 1,
	);
    wp_dropdown_categories($options); 
?>

Leave A Reply

Your email address will not be published.