Skip to content

Instantly share code, notes, and snippets.

@tamimibrahim17
Created July 18, 2018 09:44
Show Gist options
  • Save tamimibrahim17/8d926d7eb4d1285c0b960148f563d5eb to your computer and use it in GitHub Desktop.
Save tamimibrahim17/8d926d7eb4d1285c0b960148f563d5eb to your computer and use it in GitHub Desktop.
get_terms wp
<?php
include __DIR__.'/wp-load.php';
// Get all category of wordpress site.
// Categories are actually term located in `wp_terms` table.
$categories = get_terms();
// This will fetch all categories of all post type of the site.
print_r( $categories );
// How can we fetch only a specific post type categories?
// By defining taxonomy
$product_cats = get_terms(array(
'taxonomy' => 'product_cat'
));
print_r( $product_cats );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment