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.

Hi I have a custom taxonomy with a term meta flag called 'is_live' set up and I want to exclude all the terms where this flag is false when I call wp_dropdown_categories.

I've checked the codex but cant see anything relating to terms meta.

Anyone have any ideas or tried this before?

share|improve this question
    
You can do it with a filter on list_terms_exclusions. Example on that link, just adjust the ID to represent the applicable ID in place of the default category code. –  t31os Nov 29 '11 at 16:30
add comment

1 Answer

There is no direct way, hence you'll have to hack it. wp_list_categories calls get_terms internally. There's a filter terms_clauses which will allow you to modify the WHERE conditions for getting the terms. Here's how you can use it:

<?php
    add_filter('terms_clauses', 'term_filter', '', 1);

    function term_filter($pieces){

        //echo "<pre>";
        //print_r($pieces);
        //echo "</pre>";

        //You can change the entire SQL by examining the pieces array
        $pieces['where'] .= '<SQL to get the term meta>'; 

        return $pieces;
    }

    //Here's how $pieces looks like:
    Array
    (
        [fields] => t.*, tt.*
        [join] => INNER JOIN wp313_term_taxonomy AS tt ON t.term_id = tt.term_id
        [where] => tt.taxonomy IN ('category') AND tt.count > 0
        [orderby] => ORDER BY t.term_id
        [order] => ASC
        [limits] => 
    )
?>

Append your WHERE condition to the default WHERE condition. I'm not very good with SQL (honestly, I couldn't find where term meta is stored!) hence didn't write the query. For more reference you can check the file taxonomy.php (line. no. 1311) and these 2 posts: Link 1, Link 2.

Hope it helps!

share|improve this answer
add comment

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.