WordPress.org

Ready to get started?Download WordPress

Forums

More Taxonomies
Get Terms (4 posts)

  1. brian7997
    Member
    Posted 2 years ago #

    For the life of me I am can't figure this out.

    I am trying to test for a taxonomy term/tag and I can't get the test to work. ie: if this post has term/tag "my-term" then echo '';

    I have tried:

    $terms = get_terms("my_taxonomy");
     $count = count($terms);
     if ( $count > 0 ){
         echo "<ul>";
         foreach ( $terms as $term ) {
           echo "<li>" . $term->name . "</li>";
    
         }
         echo "</ul>";
     }

    I've tried has_term, has_tag, is_object_in_taxonomy and more. Nothing will list the terms. I have public queries turned on.

    I am using advanced custom fields and using custom post types. Let me know if you need more details.

    http://wordpress.org/extend/plugins/more-taxonomies/

  2. Mannie Schumpert
    Member
    Posted 2 years ago #

    I know this is fairly old, but I found that for some reason taxonomies created with this plugin just cannot be queried. I don't know what the issue is, but I discovered that if I registered the taxonomies myself in functions.php, I could query the taxonomies as expected. So it's an issue with the plugin.

    I came back to see if that issue had changed, but apparently it hasn't.

  3. phoenixMagoo
    Member
    Posted 2 years ago #

    I had the same issue today not being able to query a custom taxonomy. I figured out the 'issue' (not really sure if it's an issue). Go to Settings -> Tools -> More Taxonomies, then edit the taxonomy that you want to query. At the bottom of the screen click on the Advanced tab. The second radio button down is labeled "Allow Queries". I believe this is ticked to 'on' by default. If not, then make sure it's ticked.

    Now right under that there is a field that states: "If queries are allowed, then this is the variable to be used when querying this taxonomy" . If this field is blank, then you will not be able to query the taxonomy. I just pasted in the slug of the taxonomy that I was working with and then I was able to query the taxonomy.

    I would like to see the slug always be used by default, and then maybe use the field as a way to override if necessary.

  4. brian7997
    Member
    Posted 2 years ago #

    I am using this code below on another website to filter custom posts types in the admin. It is using a different Taxonomy plugin and works fine. I followed the suggestions to turn on queries and use the slug but to no avail. I also had using querying terms on the front end with this plugin. Something isn't working right for sure.

    function todo_restrict_manage_posts() {
        global $typenow;
        $args=array( 'public' => true, '_builtin' => false );
        $post_types = get_post_types($args);
        if ( in_array($typenow, $post_types) ) {
        $filters = get_object_taxonomies($typenow);
            foreach ($filters as $tax_slug) {
                $tax_obj = get_taxonomy($tax_slug);
                wp_dropdown_categories(array(
                    'show_option_all' => __('Show All '.$tax_obj->label ),
                    'taxonomy' => $tax_slug,
                    'name' => $tax_obj->name,
                    'orderby' => 'term_order',
                    'selected' => $_GET[$tax_obj->query_var],
                    'hierarchical' => $tax_obj->hierarchical,
                    'show_count' => false,
                    'hide_empty' => true
                ));
            }
        }
    }
    function todo_convert_restrict($query) {
        global $pagenow;
        global $typenow;
        if ($pagenow=='edit.php') {
            $filters = get_object_taxonomies($typenow);
            foreach ($filters as $tax_slug) {
                $var = &$query->query_vars[$tax_slug];
                if ( isset($var) ) {
                    $term = get_term_by('id',$var,$tax_slug);
                    $var = $term->slug;
                }
            }
        }
        return $query;
    }
    add_action( 'restrict_manage_posts', 'todo_restrict_manage_posts' );
    add_filter('parse_query','todo_convert_restrict');

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic