Category List With Comma & Link

You can use the_category if you are in the loop: <?php the_category(‘, ‘); ?> If not, then use this code: <?php $output=””; foreach((get_the_category()) as $category) { if($category->name==$homecat) continue; $category_id = get_cat_ID( $category->cat_name ); $category_link = get_category_link( $category_id ); if(!empty($output)) $output .= ‘, ‘; $output .= ‘<span class=”cat”><a href=”‘.$category_link.'”>’.$category->cat_name.'</a></span>’; } echo $output; ?>

Unpublish all posts in a category

You need to get the published posts in the category then run wp_update_post() inserting the new status. Here is a quick function. I am attaching it to admin init. I would also turn it off after your statuses are updated. function wpse_55018_get_update() { for( $i = 0; $i < 10; $i++ ) { // Runs … Read more

How to run WP_Query to retrieve attachments to posts only from a particular category?

You’ll need to first grab the posts, then grab the attachments that are children of said posts. $my_query = new WP_Query( array( ‘meta_key’ => ‘my_hash’, ‘nopaging’ => true, ‘orderby’ => ‘meta_value’, ‘fields’ => ‘ids’, ‘cat’ => ’60’, )); if ( $post_ids = $my_query->get_posts() ) { $post_ids = implode( ‘,’, $post_ids ); $atts_ids = $wpdb->get_col( “SELECT … Read more

How to mass-insert categories?

This is main function of the import process. function menu_recursive_output( $branch_objet, $parent_id, $level ) { // JUST FOR COUNTING ITEMS static $counter = 1; if ( $level ) { // CHECK IF ITEM EXISTS ALREADY // IF SO, THIS WILL RETURN ARRAY CONTAINING ID OF EXISTING ITEM $created_cat = term_exists( $branch_objet->name, ‘category’, $parent_id); // IF … Read more

Get tags specific category

If you use get_terms(), then you can retrieve all terms for a given taxonomy (this includes category as well as post-tag). To get the category on a category archive page, you can use get_category( get_query_var( ‘cat’ ) ) which will give you an object of the currently displayed cat archive page. So the actual term … Read more

Display categories inline

wp_list_categories (‘style = none’) will echo its content as it goes. It won’t pass back string that you can replace. You need to use the wp_list_categories filter to strip the <br /> tags. add_filter( ‘wp_list_categories’, function($str) { return str_replace(‘<br />’,”,$str); } ); wp_list_categories(‘style=none’);