Taxonomy, Terms, and Template Files

These types of URLs are supported since WP 3.1: register_taxonomy( ‘types’, ‘post’, array( ‘hierarchical’ => true, ‘rewrite’ => array( ‘hierarchical’ => true ), … ); Remember to flush the rewrite rules after making the change. The template you would use for both parent and child terms is taxonomy-types.php: $current_term = get_queried_object(); if ( 0 == … Read more

Make featured image required

Fairly simple using jQuery and global $typenow ex: add_action(‘admin_print_scripts-post.php’, ‘my_publish_admin_hook’); add_action(‘admin_print_scripts-post-new.php’, ‘my_publish_admin_hook’); function my_publish_admin_hook(){ global $typenow; if (in_array($typenow, array(‘post’,’page’,’mm_photo ‘))){ ?> <script language=”javascript” type=”text/javascript”> jQuery(document).ready(function() { jQuery(‘#post’).submit(function() { if (jQuery(“#set-post-thumbnail”).find(‘img’).size() > 0) { jQuery(‘#ajax-loading’).hide(); jQuery(‘#publish’).removeClass(‘button-primary-disabled’); return true; }else{ alert(“please set a featured image!!!”); jQuery(‘#ajax-loading’).hide(); jQuery(‘#publish’).removeClass(‘button-primary-disabled’); return false; } return false; }); }); </script> <?php } … Read more

Custom user role cannot see or modify featured image

Users that are only assigned to your event_admin role, don’t have the upload_files capability, needed to display the featured image meta box. Here’s the relevant code from the core: if ( $thumbnail_support && current_user_can( ‘upload_files’ ) ) // <– Notice this check add_meta_box( ‘postimagediv’, esc_html( $post_type_object->labels->featured_image ), ‘post_thumbnail_meta_box’, null, ‘side’, ‘low’ ); Note that if … Read more

Why does my custom WP role need edit_posts to edit images?

If I had to guess: because images are Attachments, and Attachments are a Post-Type. Thus, in order to edit an image, which is an attachment, which is a post, requires the edit_post capability. EDIT Don’t you have your capability mapping array keys/values reversed? e.g. you have ‘edit_posts’ => ‘edit_listings’. Shouldn’t it instead be ‘edit_listings’ => … Read more

Custom post type yearly/ monthly archive permalinks

Here’s an example using add_rewrite_rule to handle years and months for a custom post type where news is the slug. Visit the Settings > Permalinks page in admin to flush rewrite rules after this is added. You could also put this in a plugin and flush rewrite rules on plugin activation. function wpa83797_news_rewrite_rules(){ add_rewrite_rule( ‘news/([0-9]{4})/([0-9]{1,2})/?$’, … Read more