Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

If checkbox is selected, don't output taxonomy term WordPress

  • SOLVED

<strong>All of this works:</strong>

- I successfully have a list of my taxonomy terms being output using the code below. Had to use custom code because I need to show empty categories. Need to use wp_list_categories so that the current category is selected in the sidebar when you're viewing that category archive
- I'm using http://wordpress.org/extend/plugins/wp-category-meta/ to add a checkbox called <strong>hide</strong> to all of the terms.
- Some of these categories have that checkbox selected.

<strong>What I need:</strong>
- Edit the following code so that if <strong>hide=selected</strong>, don't show the category in the list.
- OR - just add a class to the LI tag so that I can hide them with CSS

THIS: should be the solution: http://wordpress.org/support/topic/how-to-add-meta-field-in-categories?replies=25

<strong>Here's my current code:</strong>

<?php
//list terms in a given taxonomy using wp_list_categories

$taxonomy = 'trend';
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 1; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';

$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'hide_empty' => 0,
'title_li' => $title
);
?>
<?php wp_list_categories( $args ); ?>

Answers (3)

2011-10-20

Jurre Hanema answers:

Try this:


<?php
global $wpdb;

$exclude = $wpdb->get_col("SELECT terms_id from {$wpdb->prefix}termsmeta WHERE meta_key = 'hide' AND meta_value = 'checked'");

$taxonomy = 'trend';
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 1; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';


$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'hide_empty' => 0,
'title_li' => $title,
'exclude' => $exclude
);

?>

<?php wp_list_categories($args); ?>


Jon comments:

Hi Jurre - this works perfectly. Thanks!

2011-10-20

Sébastien | French WordpressDesigner answers:

i think you should increase your fee

2011-10-20

Luis Cordova answers:

adding a class with a hook or something should be the way to go, there are some filters you can use