Search code examples
phparrayswordpresstaxonomycustom-post-type

what is wrong with this code - get taxonomy from theme option


I need to query posts from custom post taxonomy (set by user from WordPress theme option panel).

I am using the following code:

<?php

 if ( function_exists( 'get_option_tree') ) {
     $taxonomy = get_option_tree( 'taxonomy_option' );
 }

 $args = array(
    'project_type' => $taxonomy,
    'show_count'   => 6,
    );

 query_posts($args); 

?>      

The code is working just if I enter on 'project_type' => 'my taxonomy name'. What is wrong with the code above? How I can get an option (option-tree) into args array? Later edit: the optiontree function render the taxonomy ID.

thanks


Solution

  • The function get_option_tree() might be giving you an array, you should check it out with

    echo "<pre>".print_r($taxonomy,true)."</pre>";
    

    Update:

    After some discussion with @Ad Reactor, we found out that the $taxonomy output was a number instead of a slug. To get the slug, we can use

    $term = get_term( 1234, 'project_type' ); 
    $slug= $term->slug;
    

    where 1234 is replaced with the real term_id