Image size filtering in Media uploader according to custom post type

Add following code in your themes functions.php file function theme_set_default_image_size() { global $post_type; $custom_image_size=”medium”; if($post_type == ‘news’) $custom_image_size=”news_image_size”; else if($post_type == ‘product’) $custom_image_size=”product_image_size”; else if($post_type == ‘service’) $custom_image_size=”service_image_size”; return $custom_image_size; } add_filter( ‘pre_option_image_default_size’, ‘theme_set_default_image_size’ );

How to restrict specific post types from being read or added by specific user roles (eg. author)?

For the solution to your question, In the register_post_type arguments, use the capability_type parameter & then grant the specific capabilities to the users. For instance, if you set ‘capability_type’ => ‘supplier’, grant the edit_supplier capability to all administrators only More Details capabilities takes an array of the capabilities in the format ‘edit_post’ => ‘edit_supplier’ This … Read more

Query posts by custom post type and custom taxonomy

Pretty sure you can’t match multiple taxonomy terms in a query–Wordpress will only honor the first one and ignore the rest. Apparently, this is scheduled to be fixed in 3.1. In the meantime, there is a plugin that’ll fix you right up: http://scribu.net/wordpress/query-multiple-taxonomies EDIT: If you want a non-plugin solution, let me know. I’ve got … Read more

How to rewrite custom post type URL for multiple depths instead of one specific depth

After testing countless different structures i came up with this. It’s manual work specifying each category but gives me more control. If someone comes up with a better solution, please let me know. function mmp_rewrite_rules($rules) { //Product structure $newRules[‘product/(.+)/(.+)/(.+)/(.+)/?$’] = ‘index.php?products=$matches[4]’; //The above structure only works of the postname is the 5th uri segment //It’s … Read more

Template tags to display custom post type posts in category template?

Custom post types are by default excluded from the main query except on taxonomy pages and custom post type archives. You can simply use pre_get_posts to correctly alter the main query (alter the query variables before the SQL query is build and executed) to your needs. Just a few notes on pre_get_posts pre_get_posts runs front … Read more

Remove base slug in CPT & CT, use CT in permalink

I copied your code as-is above, pasted it into the twentysixteen theme, and changed just the post type rewrite slug from review/%brand% to %brand%. This resulted in both the term archive and review posts having your desired URL structure and successfully displaying. Now the bad news is that the rewrite rules generated for the taxonomy … Read more

Many to Many Taxonomies or rewrite rules?

With reservations, sure, you can do what you want with this code: add_action(‘init’, ‘wpse_61376_rewrites’); function wpse_61376_rewrites() { add_rewrite_rule(‘^([^/]*)/([^/]*)/?$’,’index.php?category=$matches[1]&location=$matches[2]’,’top’); } Then go to Settings → Permalinks in wp-admin and click “Save Changes” to flush your rewrites and activate this rule. Reservations The problem about not having a prefix is that any permalink with two “sections” (site.com/section-1/section-2/) … Read more

Allow Author role to publish one post type and not another

When the post type is registered, http://codex.wordpress.org/Function_Reference/register_post_type one can specify custom ‘capabilities’. eg I have an events post type, with event as a base for the capabilities, so automatically, there is a matching set like the page/post capabilties. Then one can use justin tadlock’s members plugin to assign capabilities to roles. Assign ‘create’ but not … Read more

Hook when adding or editing a specific custom post type? [closed]

There is admin_enqueue_scripts(): admin_enqueue_scripts is the first action hooked into the admin scripts actions. This hook provides a single parameter, the $hook_suffix for the current admin page. And it’s an action it can only be used to callback a specified function. Usage like: add_action( ‘admin_enqueue_scripts’, ‘function_name’ ); The codex page provides even an example on … Read more