WordPress.org

Ready to get started?Download WordPress

Forums

Category Meta plugin
Display post "if" (3 posts)

  1. alesas
    Member
    Posted 2 years ago #

    Hi,

    I added a checkbox to categories.

    I would like to display a particular list of categories: only those that have the checkbox checked.

    Do you know how to do that?
    Thx :)

    Alex

    http://wordpress.org/extend/plugins/wp-category-meta/

  2. Gyroscopic
    Member
    Posted 2 years ago #

    Hi Alex

    I have done this with the following code...

    $sql = "SELECT terms_id FROM prefix_termsmeta WHERE meta_key = 'my_key_name' AND meta_value = 'my_key_value'; ";
    
    $included_categories = $wpdb->get_col( $wpdb->prepare($sql));
    
    if ($included_categories != NULL ) {
    	// Create comma delimited list of included categories...
    	$included_categories_list = implode(", ",$included_categories);
    } 
    
    // Now get the select list of thse categories I found...
    wp_dropdown_categories('id=my_select_id&name=my_select_name&show_count=0&hierarchical=1&depth=1&show_last_update=0&hide_empty=0&include='.$included_categories_list.'&orderby=name&taxonomy=my_custom_taxonomy&echo=1');

    It uses the wp_dropdown_categories() function to display an HTML select tag populated with the taxonomy terms. (see codex for full set of arguments!) I just select all the terms I want with a simple sql statement and pass the list to the function.

    However, I have found that this plugin does not save the meta field against the term if the checkbox is empty, therefore you cannot select terms that do NOT have the checkbox checked! Which is something I am also trying to achieve :/

    Hope that helps!

  3. alesas
    Member
    Posted 2 years ago #

    Thx Gyroscopic, I'll try that :)

    Regards!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic