List of subcategories with featured image

How can I add the featured image? From what I can tell in your code, you’ve stored all category featured images in the category_images option. So you can use get_option to retrieve the featured image for each category: $image_urls = get_option( ‘category_images’, array() ); foreach ( $categories as $category ) { $cat_id = $category->term_id; $image_url … Read more

Get child categories when clicking on parent category

Grab the parent category $category = get_category_by_slug( ‘category-name’ ); Set whatever args you need for your post query, but make sure to include the child_of arg $args = array( ‘type’ => ‘post’, ‘child_of’ => $category->term_id, ‘hierarchical’ => 1, ‘taxonomy’ => ‘category’, ); Get your subcategories based on these args $child_categories = get_categories($args); You’ll get an … Read more

How can I prevent users from creating new categories?

You should to remove a capability named ‘manage_categories’ from user role or roles, for example: /** * Don’t let subscribers add/edit/remove categories. * * You should call the function once when your plugin or theme is activated. * * @uses WP_Role::remove_cap() */ function remove_subscribers_manage_categories() { // get_role returns an instance of WP_Role. $role = get_role( … Read more

adding custom fields to next and previous post link

Here’s the code for what you’re trying to do (accessing post custom value): <?php global $post; $prev_post = get_adjacent_post(); $next_post = get_adjacent_post( false, ”, false ); $prev_post_id = $prev_post->ID; $next_post_id = $next_post->ID; // this should, according to your code above, be the http://example.com/your/img.jpg string $prev_img_path = get_post_custom_values( ‘your_key_name’, $prev_post_id ); $next_img_path = get_post_custom_values( ‘your_key_name’, $next_post_id … Read more

Automated adding of one tag to all the posts in a category

A good starting point is (as always) the Codex function reference. There’s one nice little function that can be used to add tags or categories (or whatever built-in or custom taxonomy) to a post: wp_set_object_terms();. Maybe wp_set_post_terms(); is more easy to use. Further explanation can be found when you follow the link. There are multiple … Read more

Assigning a category to a user role

This may be similar to what you are looking for, it doesn’t force a category, but doesn’t let the user submit the new post unless at least one category is selected This solution requires jQuery, but with little modification can be ported to plain JavaScript //intercept the “update” or “publish” button $(“#post”).submit(function(e){ //grab the GET … Read more