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

  1. alesas
    Posted 4 years ago #


    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 :)



  2. Gyroscopic
    Posted 4 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...

    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
    Posted 4 years ago #

    Thx Gyroscopic, I'll try that :)


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Category Meta plugin
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic