Answers.Body: <p>Depending on what you are searching by, you can use something similar to this. You can see the properties you can search by <a href="http://buildwithcraft.com/docs/templating/craft.categories" rel="nofollow">in the documentation</a>.</p>
  
  <pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Category);
  $criteria-&gt;group = 'CategoryGroupName';
  $criteria-&gt;title = 'CategoryTitle';
  $criteria-&gt;limit = 1;
  
  $category = $criteria-&gt;find();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-20T16:37:57.547Z
Answers.Text: Doesn't **craft()->elements->getCriteria(ElementType::Category);** technically load all categories? If so I want to avoid the overhead.
Answers.UserDisplayName: Matt V
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-20T16:41:41.430Z
Answers.Text: Nope! It loads an element criteria model of type Category. That simply allows you to query against Category properties like group, title, level, etc. ([source](https://github.com/pixelandtonic/Craft-Release/blob/master/app/services/ElementsService.php#L33))
Answers.UserDisplayName: Aaron Berkowitz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-20T16:47:54.780Z
Answers.Text: Oh ok. Cool. I'll give this a try.
Answers.UserDisplayName: Matt V
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-28T20:14:10.727Z
Answers.Text: Question: How would I get only the children of a given category? What I mean is... I have a list of countries and under them their states/provinces. Is it possible to do something like **$criteria->children = 1**? I've tried this and it doesn't work.
Answers.UserDisplayName: Matt V
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-28T20:20:19.313Z
Answers.Text: You can limit the search to what [`level`](https://buildwithcraft.com/docs/templating/craft.categories#level) the category is. So if you know you just want categories of the second level (states/provinces), you can add `$criteria->level = 2` before you run `find()`
Answers.UserDisplayName: Aaron Berkowitz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-29T13:07:10.850Z
Answers.Text: I've done that but I also get the states/provinces from other countries. I assume that **$criteria->level = 2** gets all level 2 items regardless of the parent. At least that has been my experience.
Answers.UserDisplayName: Matt V
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-29T13:09:52.547Z
Answers.Text: That's correct. You can limit your search even more if you have the country you want the states from by adding `$criteria->descendantOf = $country`
Answers.UserDisplayName: Aaron Berkowitz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-29T13:22:05.073Z
Answers.Text: Oh ok. It seems to me then that I have to first get the country, then use that data to get the descendantOf. Is there a way to do this all in one shot or do I need to get country then use that result on a second query?
Answers.UserDisplayName: Matt V
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-29T15:02:02.000Z
Answers.Text: Yeah, you will need to first get the parent category, then get the children in two separate finds. If you are going to be running these steps frequently, I highly recommend cacheing the process. You can see a simple cache example in [this service](https://github.com/aberkie/craft-summit-api/blob/master/disney/services/Disney_InterestService.php) I made for the Craft CMS summit.
Answers.UserDisplayName: Aaron Berkowitz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-29T17:42:37.560Z
Answers.Text: No problem! If this is working for you, can you select the answer as the correct answer so we can close out your question?
Answers.UserDisplayName: Aaron Berkowitz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-29T19:03:33.660Z
Answers.Text: Not really sure how to do that, but I marked it as userful
Answers.UserDisplayName: Matt V
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-20T16:32:19.220Z
Answers.LastActivityDate: 2015-04-20T16:49:25.640Z
Answers.LastEditDate: 2015-04-20T16:49:25.640Z
Answers.UserDisplayName: Aaron Berkowitz
Body: <p>I have a category that I'm trying to load via a plugin. Looking at the categories service I see there is a function called "getCategoryById" but I don't know what the ID is so instead I'm loading the category group thinking that the ID provided there is what I need, apparently it is not.</p>
  
  <p>Kinda of stumped on this one. Any advice?</p>
  
  <p>Thanks,</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-20T16:28:45.887Z
Comments.Text: Hey Matt - what infomormation do you have about the category? Name, level, slug?
Comments.UserDisplayName: Aaron Berkowitz
Tags: <plugin-development><categories>
Title: Load Category in Plugin
ThreadText: # Load Category in Plugin
  
  (Asked by: username_0 on 2015-04-20)
  
  I have a category that I'm trying to load via a plugin. Looking at the categories service I see there is a function called "getCategoryById" but I don't know what the ID is so instead I'm loading the category group thinking that the ID provided there is what I need, apparently it is not.
  
  Kinda of stumped on this one. Any advice?
  
  Thanks,
  
  **Tags:** plugin-development, categories
  
  > **Comments:**
  > **username_1**: Hey username_0 - what infomormation do you have about the category? Name, level, slug?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-04-20. Score: 2
  
  Depending on what you are searching by, you can use something similar to this. You can see the properties you can search by [in the documentation](http://buildwithcraft.com/docs/templating/craft.categories).
  
  ```
  $criteria = craft()->elements->getCriteria(ElementType::Category);
  $criteria->group = 'CategoryGroupName';
  $criteria->title = 'CategoryTitle';
  $criteria->limit = 1;
  
  $category = $criteria->find();
  
  ```
  
  > **Comments:**
  > **username_0**: Doesn't **craft()->elements->getCriteria(ElementType::Category);** technically load all categories? If so I want to avoid the overhead.  
  > **username_1**: Nope! It loads an element criteria model of type Category. That simply allows you to query against Category properties like group, title, level, etc. ([source](https://github.com/pixelandtonic/Craft-Release/blob/master/app/services/ElementsService.php#L33))  
  > **username_0**: Oh ok. Cool. I'll give this a try.  
  > **username_0**: Question: How would I get only the children of a given category? What I mean is... I have a list of countries and under them their states/provinces. Is it possible to do something like **$criteria->children = 1**? I've tried this and it doesn't work.  
  > **username_1**: You can limit the search to what [`level`](https://buildwithcraft.com/docs/templating/craft.categories#level) the category is. So if you know you just want categories of the second level (states/provinces), you can add `$criteria->level = 2` before you run `find()`  
  > **username_0**: I've done that but I also get the states/provinces from other countries. I assume that **$criteria->level = 2** gets all level 2 items regardless of the parent. At least that has been my experience.  
  > **username_1**: That's correct. You can limit your search even more if you have the country you want the states from by adding `$criteria->descendantOf = $country`  
  > **username_0**: Oh ok. It seems to me then that I have to first get the country, then use that data to get the descendantOf. Is there a way to do this all in one shot or do I need to get country then use that result on a second query?  
  > **username_1**: Yeah, you will need to first get the parent category, then get the children in two separate finds. If you are going to be running these steps frequently, I highly recommend cacheing the process. You can see a simple cache example in [this service](https://github.com/aberkie/craft-summit-api/blob/master/disney/services/Disney_InterestService.php) I made for the Craft CMS summit.  
  > **username_1**: No problem! If this is working for you, can you select the answer as the correct answer so we can close out your question?  
  > **username_0**: Not really sure how to do that, but I marked it as userful  
  
  ---
  
  