Fetch WordPress Categories

Now Days WordPress is a popular blogging platform which have many inbuilt functions.For fetching wordpress categories, wordpress provide lots of inbuilt functions like get_categories(), wp_list_categories(), wp_dropdown_categories().

 

A. get_categories()
Using This function we can fetch wordpress categories.

//Fetching categories in string format.
<?php
   get_categories(style=list&hide_empty=1);
?>
//Fetching categories in object format.
<?php
   $options = array('style' => 'list','hide_empty' => 1,);
   get_categories($options);
?>

 

B. wp_list_categories()
Using This function we can fetch wordpress categories in html format.

//Fetching categories in string format.
<?php
   wp_list_categories(style=list&hide_empty=1);
?>
//Fetching categories in object format.
<?php
   $options = array('style' => 'list','hide_empty' => 1,);
   wp_list_categories($options);
?>

 

C. wp_dropdown_categories()
Using This function we can fetch 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.
<?php
   $options = array('style' => 'list','hide_empty' => 1,);
   wp_dropdown_categories($options);
?>

 

Categories

Related Blogs

Disable Repeat Purchase Of Product

To disable repeat purchase of products in WooCommerce, you can implement a custom solution using a combination of code snippets and WooCommerce hooks. The idea is to prevent customers from adding the same product to the cart if it already exists in the cart. Below are the steps to achieve this:

To list down future posts in WordPress

To list down future posts in WordPress, you can use the `WP_Query` class to customize the query and fetch future posts. The future posts are the ones with a post status of “future,” and their publication date is scheduled in the future.

WooCommerce: Get Product Info (ID, SKU, $) From $product Object

In WooCommerce, the `$product` object represents a single product, and it contains various information and methods that you can access to get details about the product. Here is a list of common product information that you can retrieve from the `$product` object: