0

I tried to get categories directly from phpmyadmin, but i can't. then i tried to create this php scrip in public_html

include "wp-includes/category-template.php";

$args = array(
    'hide_empty' => 0,
    'pad_counts' => true
);
$categories = get_categories( $args );
foreach($categories as $category) {

    if($category->count == 0) {
        echo $category->name."<br />";
    } else {
        // do nothing
    }

}
?>

but it's return Fatal error: Call to undefined function get_categories() in /mnt/env/*****/development/public_html/test.php on line 9

0

Is there a specific reason you're trying to do this outside of WordPress the normal way? If there is, you could do include('wp-load.php') to access WordPress functions.

But that would only be if you have to access WordPress externally. Normally your code would either go into your theme's functions.php file, or you would add your code to a custom plugin.

2
  • big thanks, i'm trying to build an mobile app for my site, but this script don't return fixed categories in dropdown, do you have any idea? – Houssam Sep 30 '15 at 15:50
  • If you're using WordPress to build a mobile app, I would check out the WP REST API here: github.com/WP-API/WP-API It isn't part of the WordPress core yet, but it will be soon. – Nate Allen Sep 30 '15 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.