Title: get_category_link from a Theme Options variable
Last modified: August 19, 2016

---

# get_category_link from a Theme Options variable

 *  Resolved [Erik Ford](https://wordpress.org/support/users/wearepixel8/)
 * (@wearepixel8)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/get_category_link-from-a-theme-options-variable/)
 * I am developing a theme that uses theme options to populate the Home page with
   a custom query. I would also like to have a link back to the admin’s chosen category
   so you can browse the archives. I am using `<?php echo get_category_link( $category[
   0]->cat_ID ); ?>` which is fine if all of the posts are in the selected category.
   But, if a post resides in multiple categories, this fails. If there a way I can
   get the category link within my custom query based on the theme option chosen?
   Here is the query I came up with. Any and all help is truly appreciated.
 *     ```
       <?php $block_one = new WP_Query('category_name='. get_option('wap8_block1') .'&showposts=1&caller_get_posts=1');
       while ( $block_one -> have_posts() ) : $block_one -> the_post();
       $category = get_the_category(); ?>
       ```
   

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/get_category_link-from-a-theme-options-variable/#post-1804729)
 * Take a look at [get_category_link()](http://codex.wordpress.org/Function_Reference/get_category_link).
   The example shows how to get the category ID from the category name using get_cat_ID()
   and you apparently have the category name in your option.
 *  Thread Starter [Erik Ford](https://wordpress.org/support/users/wearepixel8/)
 * (@wearepixel8)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/get_category_link-from-a-theme-options-variable/#post-1804737)
 * I did try to set up the following variables, which failed miserably:
 *     ```
       $cat_name = get_option('wap8_block1');
       $cat_id = get_category_id($cat_name);
       $cat_link = get_category_link($cat_id);
       ```
   
 * Then, inside of the loop, I have `<a href="<?php echo $cat_link; ?>">`. This 
   returns nothing and breaks this and all subsequent loops. Any suggestions? Thanks
   again.
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/get_category_link-from-a-theme-options-variable/#post-1804738)
 * I think the function you need is get_cat_ID():
 *     ```
       $cat_name = get_option('wap8_block1');
       $cat_id = get_cat_ID($cat_name);
       $cat_link = get_category_link($cat_id);
       ```
   
 *  Thread Starter [Erik Ford](https://wordpress.org/support/users/wearepixel8/)
 * (@wearepixel8)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/get_category_link-from-a-theme-options-variable/#post-1804747)
 * It’s at this moment that I realize that I have been looking at this code for 
   way too long. **Thanks so much**. Sometimes I need someone else to look at the
   bonehead mistakes and help.
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/get_category_link-from-a-theme-options-variable/#post-1804751)
 * One of Murphy’s laws: The longer you work on a problem, the more likely it is
   that a casual observer will immediately spot the answer! 🙂

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘get_category_link from a Theme Options variable’ is closed to new replies.

## Tags

 * [custom-query](https://wordpress.org/support/topic-tag/custom-query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [15 years, 6 months ago](https://wordpress.org/support/topic/get_category_link-from-a-theme-options-variable/#post-1804751)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
