If in category to be inside of a function

If you want to use the function to output the code somewhere: function displayImage($currentPost) { // Show the featured icon only if current post is in “featured” category if ( in_category ( ‘featured’, $currentPost ) ) { $output=”<a href=”https://wordpress.stackexchange.com/questions/58811/<?php the_permalink(); ?>”> <span class=”featured_icon”> <img src=”<?php bloginfo(“template_directory’); ?>/images/featured_icon.png” /> </span> </a>’; } else { $output=”” }; … Read more

Add Post Screen Keep Category structure

Yup. Use the add_meta_boxes_post to add a new category metabox that preserves the structure and while you’re at it, remove the default one, like this: add_action( ‘add_meta_boxes_post’, ‘fix_hierarchical_post_categories_metaboxes’, 10, 1 ); And here’s the callback: /* * This include provides an alternative post category metabox that sets the checked_ontop argument of wp_terms_checklist to false. * … Read more

How to use wp_category_checklist()?

Here is the answer I ended up with: $select_cats = wp_dropdown_categories( array( ‘echo’ => 0 ) ); $select_cats = str_replace( “name=”cat” id=”, “name=”cat[]” multiple=”multiple” id=”, $select_cats ); echo $select_cats; It displays a list of my categories that can be multi-selected as per my question. It’s a hack of wp_dropdown_categories, but it works.

get all sub categories without specify any category

You could use get_categories(). Returns an array of category objects matching the query parameters. Arguments are pretty much the same as wp_list_categories and can be passed as either array or in query syntax. // Fetch parent categories $parent_categories = get_categories( ‘parent=0’ ); foreach ( $parent_categories as $parent_category ) { // Fetch child categories $args = … Read more