Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to access a list of all categories for a plugin I'm working on, I know that there is the wp_list_categories template tag for use in themes. What would be the best way of accessing these categories for use in a plugin? Is there a specific function or is it a case of writing a specific query?

Edit: Here's a screenshot which shows the context of how I'm trying to display a list of categories:

alt text

share|improve this question

1 Answer 1

up vote 1 down vote accepted

The get_categories() function is what you're looking for.

Update: Thanks for the clarifications. Sounds like you're doing the same thing as this question, ie. creating a new taxonomy for attachments. (I'm not sure they get these categories automatically, maybe someone else can clarify.) I haven't played with that functionality yet, but does that other post sound like what you're looking for?

share|improve this answer
    
Thanks, I think I'm partially trying to get up to speed with what is accepted best practice for using various functions, whether they are appropriate for use only within themes or also within plugins. The wp_dropdown_categories function will render a dropdown menu containing all my categories, but is this an acceptable function to user within a plugin? –  Rick Curran Aug 20 '10 at 10:02
    
Sure. Plenty of plugins provide content to widgets, or modify post body content based on a shortcode or filter. You may need to rely on the 'echo' argument to wp_dropdown_categories() depending on how your plugin is written (if it needs to return the html, or output it immediately). –  Annika Backstrom Aug 20 '10 at 10:07
    
Ok, that's good to know. I think it's because I've used private and public (frontend and backend) functions in my custom PHP development before that I just wanted to make sure that there wasn't some specific plugin / backend functions that should be used. wp_dropdown_categories seems to work pretty well for what I want though I think. –  Rick Curran Aug 20 '10 at 10:17
    
You can also use wp_dropdown_categories() to retrieve custom taxonomies (in the event you have a different style/set of categories that are used in your plug-in). Pass the name of the taxonomy in the options array indexed as taxonomy ... otherwise the taxonomy defaults to "category." –  EAMann Aug 20 '10 at 18:24
    
However, do note that when using a taxonomy other than category the option values are names, where as they are numeric IDs when showing categories. –  t31os Dec 2 '10 at 11:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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