WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am having some issues with querying the output of custom taxonomies in my theme options.

I have included what I think are the necessaries below.

Many thanks for your help in advance.

// Pull all the custom taxonomies into an array

$options_taxonomies = array();
$taxonomies_terms_obj = get_terms('portfolio_category');
foreach ($taxonomies_terms_obj as $taxonomy) {
    $options_taxonomies[$taxonomy->term_id] = $taxonomy->name;

// Select a Featured Homepage Category

$options[] = array(
    'name' => __('Featured Homepage Category', 'options_framework_theme'),
    'desc' => __('Choose a category to feature on your homepage.', 'options_framework_theme'),
    'id' => 'homepage_feature',
    'type' => 'select',
    'options' => $options_taxonomies);

//The query

if ( function_exists( 'of_get_option' ) ) :
    query_posts( 'cat=' . $homepage_feature = of_get_option( 'homepage_feature' ) . '&posts_per_page=3' ); 
share|improve this question
up vote 0 down vote accepted

I see three things.

if ( function_exists( 'of_get_option' ) ) :
    query_posts( 'cat=' . $homepage_feature = of_get_option( 'homepage_feature' ) . '&posts_per_page=3' ); 
  1. You have a syntax error. There is no endif;. Maybe that is a typo, but maybe not. If you are trying to write a one-line if, remove the colon.
  2. Your title states "custom taxonomy". cat= is for categories, not general taxonomies. See the Codex.
  3. Use WP_Query, not query_posts

Assuming the rest of the code works, and assuming I am reading it right, your query should be:

if ( function_exists( 'of_get_option' ) ) {
  $args = array(
    'posts_per_page' => 3,
    'tax_query' => array(
            'taxonomy' => 'your-taxonomy-name',
            'field' => 'id', // or slug; I don't know which you have
            'terms' => of_get_option( 'homepage_feature' )
  $my_qry = new WP_Query($args); 
share|improve this answer
This works but only displays a link to Home? and does not pull out the taxonomies as defined in the $options_taxonomies – Dean McCann Feb 12 '13 at 15:09
WP_query does not display a link at all. It returns an Object. I don't know what you mean. – s_ha_dum Feb 12 '13 at 15:12
Thanks, yes, I had a syntax error on the if statement. Sorry, the taxonomies are being listed in my options.php fine, but wont work with the query. If I query an array using get_categories it works fine? If it helps my arrays are in a template named options.php with the query in front-page.php – Dean McCann Feb 12 '13 at 15:20
Post the output from of_get_option( 'homepage_feature' ); – s_ha_dum Feb 12 '13 at 15:25
Wow... that got scrambled. Sorry. Let me try again. Post the content of var_dump(of_get_option( 'homepage_feature' )); – s_ha_dum Feb 12 '13 at 15:35

Your Answer


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.