How To Get Parent Category Slug of Current Post

You will need to use the ID value returned by $category[0]->category_parent and pass it through get_term(). Example: $category = get_the_category(); $category_parent_id = $category[0]->category_parent; if ( $category_parent_id != 0 ) { $category_parent = get_term( $category_parent_id, ‘category’ ); $css_slug = $category_parent->slug; } else { $css_slug = $category[0]->slug; }

Get posts from sites in Multisite?

The WordPress function switch_to_blog() expects an integer as an input parameter. You can read more about it in the Codex: http://codex.wordpress.org/Function_Reference/switch_to_blog Please try this kind of structure instead: // Get the current blog id $original_blog_id = get_current_blog_id(); // All the blog_id’s to loop through $bids = array( 1, 2 ); foreach( $bids as $bid ) … Read more

Get the children of the parent category

You can’t just pass the string “parent” to get_categories. You have to pass the ID of the parent. $categories=get_categories( array( ‘parent’ => $cat->cat_ID ) ); Notice that there are two similar but not equal “get child” parameters that you can use. child_of (integer) Display all categories that are descendants (i.e. children & grandchildren) of the … Read more

WordPress Multisite – global categories

function __add_global_categories( $term_id ) { if ( get_current_blog_id() !== BLOG_ID_CURRENT_SITE || ( !$term = get_term( $term_id, ‘category’ ) ) ) return $term_id; // bail if ( !$term->parent || ( !$parent = get_term( $term->parent, ‘category’ ) ) ) $parent = null; global $wpdb; $blogs = $wpdb->get_col( “SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = ‘{$wpdb->siteid}'” ); foreach … Read more

Get Category ID inside Category template

$wp_query->get_queried_object() will give you the “currently queried object”. On a category archive this is the category object, on a author page this is the author, on a single post this is the post itself, … well, you get the the idea. If you only want the ID you can also use $wp_query->get_queried_object_id().

Add custom field to Category

I posted an How To about it a week ago http://en.bainternet.info/2011/wordpress-category-extra-fields hope this helps. Ohad. Here are the details of the post: The first thing we need to do is add the extra fields to the category edit form using the hook edit_category_form_fields and we use a simple function that will print out the extra … Read more

How To Find Out WordPress Category Table in MYSQL?

See the Codex’s WordPress Taxonomy documentation. WordPress 2.3 replaced the previous categories, post2cat, and link2cat tables with three a more flexible set of taxonomy tables. wp_terms wp_term_relationships wp_term_taxonomy wp_terms– holds the basic information about single terms. term_id bigint(20) unsigned NOT NULL auto_increment, name varchar(200) NOT NULL default ”, slug varchar(200) NOT NULL default ”, term_group … Read more

List all subcategories from category

Yes, you can use get_categories() using ‘child_of’ attribute. For example all sub categories of category with the ID of 17: $args = array(‘child_of’ => 17); $categories = get_categories( $args ); foreach($categories as $category) { echo ‘<p>Category: <a href=”‘ . get_category_link( $category->term_id ) . ‘” title=”‘ . sprintf( __( “View all posts in %s” ), $category->name … Read more