• Resolved justinblayney

    (@justinblayney)


    Hello, As the title states, I am tying to list the taxonomy categories for a specific custom post type created by this plugin, her tis my code so far, no luck.

    
        <select name="event-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> 
        <option value=""><?php echo esc_attr(__('Select Category')); ?></option> 
    
        <?php 
            $option = '<option value="' . get_option('home') . '/category/">All Categories</option>'; // change category to your custom page slug
            $categories = get_categories( array(
    			'orderby' => 'name',
    			'order'   => 'ASC',
    			'taxonomy' => 'firm_type'
    		) );
    		
            foreach ($categories as $category) {
                $option .= '<option value="'.get_option('home').'/category/'.$category->slug.'">';
                $option .= $category->cat_name;
                $option .= ' ('.$category->category_count.')';
                $option .= '</option>';
            }
            echo $option;
        ?>
    </select>
Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Biggest thing I’m seeing there is that if you’re trying to retrieve the terms associated with a given post, then you’re using the wrong function since get_categories would simply fetch the terms created for the specified taxonomy.

    However, if that is what you’re for sure doing, I’m not able to presently determine why you’re not receiving results. We don’t do anything that should prevent a function like get_categories from working and finding results.

    Thread Starter justinblayney

    (@justinblayney)

    Michael,

    I have a custom post type called companies,
    It has categories (firm_type) created by your plugin that only show for companies

    I want to show all the firm_types in a drop down list so people can do a company search. Please point me in the direction of working code that will show all the categories associated with companies

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    As far as I’ve always been aware, you’re on the right general track, so I don’t really have a case of “working code” vs what you’re trying above. Best guess I have is that you haven’t assigned any terms to posts yet, and the “hide_empty” argument is defaulting to true. Perhaps add 'hide_empty' => false to your get_categories arguments

    Thread Starter justinblayney

    (@justinblayney)

    That was it, thank you…

    now hopefully I wont have similar problems with my meta_query on the search results page, but that is for next week…

    • This reply was modified 4 years, 12 months ago by justinblayney.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    winning! have a good weekend.

    how can i get a particular category in list.. pls tell me the shortcode to use for this function

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    @princerocky I don’t have anything readymade and would need more details about what you’re trying to accomplish to potentially scaffold something for you. If you can provide some extra insight, I can do what I can to create something.

    @michaelbeckwith I m trying show one category inside post but when applying list category code then all categories are displaying in post, so pls tell how to show only particular category inside post and not showing others. HOPE I HAVE EXPLAINED MY QUESTION ..Thanks IN advance

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Assuming you mean https://developer.wordpress.org/reference/functions/wp_list_categories/ then that function isn’t the best one to use if you’re say trying to just display a list of categories assigned to a given post. You’d want to use something like https://developer.wordpress.org/reference/functions/get_the_category_list/

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘list taxonomy categories of custom post types’ is closed to new replies.