Check if post belongs to any category
You can use is_object_in_term(). Despite name it can also check for taxonomy match if terms are omitted. is_object_in_term( get_the_ID(), ‘category’ );
You can use is_object_in_term(). Despite name it can also check for taxonomy match if terms are omitted. is_object_in_term( get_the_ID(), ‘category’ );
There’s an argument called hide_empty which is true by default. $args = array(‘hide_empty’ => FALSE); wp_list_categories($args); Codex: wp_list_categories()
You could try out Scribu’s plugin, i believe this addresses the very problem you’re describing which has been reported on Trac a handful of times(but closed/deleted). Category Checklist Tree by scribu http://wordpress.org/extend/plugins/category-checklist-tree/ Related tickets: http://core.trac.wordpress.org/ticket/14723 http://core.trac.wordpress.org/ticket/10982 Hope that helps.. 🙂
You can make use of the hide_empty argument of get_terms(). It’s default value is set to true. Do it somewhat like this: $args = array( ‘hide_empty’ => false ); $terms = get_terms( ‘wpsc_product_category’, $args );
The new separator attribute of wp_list_categories() I think you are looking for the new separator attribute, that will be introduced here in WordPress 4.4 that’s just around the corner. I located the trac ticket here #9025. Then you can use: $args = [ ‘style’ => ‘none’, ‘separator’ => ”, // <– Removes the default one … Read more
As I said, we would rather use native functions here, which is safer and already does all the hard work for you. We need to be very careful here as this is a very expensive operation to run. Not doing this correctly can crash your site due to timing out Your worksflow is also wrong … Read more
$categories = get_the_category(); if ( ! empty( $categories ) ) { echo ‘<a href=”‘ . esc_url( get_category_link( $categories[0]->term_id ) ) . ‘”>’ . esc_html( $categories[0]->name ) . ‘</a>’; }
Under screen options on the Product Categories page, change the number of product categories to something big enough to get job done; drag and drop to order; change back to 20 or something manageable.
You can add something like this in your category.php. if ( ! is_admin() ) { wp_redirect( home_url() ); exit; } This will redirect viewers to website homepage but category pages will be active and accessable to admins only.
Here’s snippet to display first category from post. $category = get_the_category(); if ( $category[0] ) { echo ‘<h2><a href=”‘ . get_category_link( $category[0]->term_id ) . ‘”>’ . $category[0]->cat_name . ‘</a></h2>’; } Original idea of the code is from WordPress Codex