I want to achieve something like this:
admin can create taxonomy. (already have)
admin assign a taxonomy to specific vendor. (already have)
vendor can create more taxonomy, with an extra field keeping track that the taxonomy belongs to that specific vendor.
Now i'm in the mist giving permission to vendor to edit taxonomy, and the logic behind. I have the following code in my includes/taxonomy.php in my plugin:
function WCPVPlus_register_taxonomy_args( $args, $taxonomy, $object_type ) {
if(MY_TAXONOMY===$taxonomy){
$args['capabilities'] =array(
'manage_terms' => 'read',
'edit_terms' => 'read',
'delete_terms' => 'read',
'assign_terms' => 'read',
);
};
return $args;
}
add_filter('register_taxonomy_args', 'WCPVPlus_register_taxonomy_args', 10, 3);
then in my main php file, i have this in the init method:
include_once('includes/taxonomy.php');
The code doesn't seem to work, as when i debug using xdebug, the code doesn't stop at WCPVPlus_register_taxonomy_args function.
Is there anyone here to explain the concept behind and enlighten me in achieving what i'm trying to do?
Related
I have a problem with my 2 custom wordpress taxonomies.
I've created a custom post type called "kurs" and for this custom post type i've also created 2 custom hierarchical taxonomies. This worked fine until I wanted to add custom capabilities for the 2 taxonomies.
I've added the "capabilities" argument for the 2 capabilities
first taxonomy:
'capabilities' => array(
'manage_terms' => 'manage_location',
'edit_terms' => 'edit_location',
'delete_terms' => 'delete_location',
'assign_terms' => 'assign_location',
)
second taxonomy:
'capabilities' => array(
'manage_terms' => 'manage_typ',
'edit_terms' => 'edit_typ',
'delete_terms' => 'delete_typ',
'assign_terms' => 'assign_typ',
)
Then i added all these new custom capabilities to the administrator role with this function:
function kurse_role_caps() {
// gets the simple_role role object
$role = get_role('administrator');
// add a new capability
$role->add_cap( 'manage_location', 'edit_location', 'delete_location', 'assign_location', 'manage_typ', 'edit_typ', 'delete_typ', 'assign_typ', true);
}
add simple_role capabilities, priority must be after the initial role definition
add_action('init', 'kurse_role_caps', 11);
But the second custom taxonomy does not show up in the admin menu even though i set the argument 'show_in_menu' to true :Screenshot of my admin menu
If i remove the custom capabilites from the second taxonomy it shows up in the admin:
enter image description here
After I searched this problem on the internet no one had a similar problem. Here is my gist for the full code i use for the custom post type and the 2 custom taxonomies: https://gist.github.com/jeremygrlj/a9319591e3d1940e9ef465f024220e84
Please note that add_cap only accept one capability as string and so you have to loop all capabilities. Change your function like this.
function kurse_role_caps() {
// gets the simple_role role object
$role = get_role('administrator');
// add a new capability
$capabilities = array( 'manage_location', 'edit_location', 'delete_location', 'assign_location', 'manage_typ', 'edit_typ', 'delete_typ', 'assign_typ' );
foreach( $capabilities as $cap ) {
$role->add_cap( $cap );
}
}
// add simple_role capabilities, priority must be after the initial role definition
add_action('init', 'kurse_role_caps', 11);
This is what I have to query all events...
query_posts("post_type=marcato_show&meta_key=marcato_show_start_time_unix&orderby=meta_value&order=ASC&posts_per_page=999" );
and this works, just getting the community events...
query_posts( "post_type=marcato_show&showtype=community-events&meta_key=marcato_show_start_time_unix&orderby=meta_value&order=ASC&posts_per_page=999" );
how do I go about getting all the events WITHOUT the community events?
Rather than using query_posts(), which can cause a number of issues (see here and here), I'd recommend using the WP_Query class.
This will avoid some obscure bugs, speed up the query for you, and also make it easier to make changes like excluding posts assigned to a certain term (in this case, the community-events term of the showtype taxonomy).
Be sure to read up on the WP_Query documentation as it covers a lot of useful arguments you may need in the future. But for now, here's how you'd run your same query, excluding those posts in community-events:
$posts = new WP_Query(array(
"post_type" => "marcato_show",
"meta_key" => "marcato_show_start_time_unix",
"orderby" => "meta_value",
"order" => "ASC"
"posts_per_page" => 999, // you can also use `-1` to return unlimited results
"tax_query" => array(
array(
"taxonomy" => "showtype",
"field" => "slug",
"terms" => "community-events",
"operator" => "NOT IN",
),
),
));
if($posts->have_posts()){
while($posts->have_posts()){
$posts->the_post();
// DISPLAY YOUR POSTS HERE
}
wp_reset_postdata(); // restore original post data
This is querying with the same arguments you used in your original post, with the added tax_query to query posts not in that custom taxonomy term. Scroll down to Taxonomy Parameters at the WP_Query documentation linked above for full details on how this works.
I am using Members plugin to manage User Groups (restrict pages/posts for specific user group) now to show the links to that user group in back-end I need a plugin for creating Custom Menu where the allowed pages/posts links will be shown (back-end) for the specific user group.
Sorry, dont know exatly which plugin or code would solve your problem.
But here are some resources:
http://codex.wordpress.org/Roles_and_Capabilities#Resources
http://wordpress.org/extend/plugins/tags/capability
Well what I do is to add this script in my theme's function.php
// Admin bar menu w.r.t role
function wp_admin_bar_new_item() {
global $wp_admin_bar;
if (current_user_can('contractor')){
$wp_admin_bar->add_menu(array(
'id' => 'wp-admin-bar-new-item',
'title' => __('Contractor Menu'),
'href' => 'http://my_site/contractor/'
));
} elseif (current_user_can('consultant')) {
$wp_admin_bar->add_menu(array(
'id' => 'wp-admin-bar-new-item',
'title' => __('Consultant Menu'),
'href' => 'http://my_site/consultant/'
));
}
}
add_action('wp_before_admin_bar_render', 'wp_admin_bar_new_item');
and fix my issue.
I'm customizing the admin on a new WP site, and I am creating an over-arching custom post type, that will allow the admin to create pages for the site. I want them to be able to pull values from other custom post types and set them here. I'm struggling to find good documentation on how to do this though. I can create multiple custom post types without a problem, just unsure how to pull the values of post_type_y into the meta_options for post_type_x.
Any and all help is appreciated!
Since I can't 'comment' on your question, I'll do my best to answer it as I understand it..
There's a plugin posts to posts that will allow you to associate Post 1 with Post 2. It's a little clunky, but gets the job done.
If you're looking to associate tags, categories or whatever between multiple post-types, I prefer using custom taxonomies as they are relatively easy to implement.
Sample Custom Taxonomy:
function languages_init() {
// create a new taxonomy
register_taxonomy(
'languages',
array('post','clients','positions','projects'), // Set various post-types
array(
'label' => __( 'Languages' ),
'sort' => true,
'args' => array( 'orderby' => 'term_order' ),
'rewrite' => array( 'slug' => 'language' )
)
);
}
add_action( 'init', 'languages_init' );
I have the following code to build a custom taxonomy for my portfolio:
add_action( 'init', 'create_pc_db_taxonomies', 0 );
function create_pc_db_taxonomies() {
register_taxonomy( 'type', 'post', array( 'hierarchical' => true, 'label' => 'Type', 'query_var' => true, 'rewrite' => array( 'slug' => 'type' ) ) );
}
I have created a portfolio category on my site (I removed the /category/ base) and have created some items and set the custom taxonomies against them. So I get the following setup:
http://domain.com/portfolio/item1/ but what I want is for the taxonomy links to look like this: http://domain.com/portfolio/type/web and then this will show a list of portfolio items related to the that type. At the moment they are root like http://domain.com/type/web these create 404's, but I have also tried adding 'portfolio/type' as the taxonomy slug but it just creates a 404 as well, but i'm pretty sure this is the wrong way of doing it anyways. Any help?
Thanks
EDIT: The site is here: http://driz.co.uk/ all the work is in a category called Portfolio and under each pic is the title and custom taxonomy (if you click on them you will get the 404)
Make sure all plugins are disabled (at least ones that tweak with rewrites), and delete the option rewrite_rules in your wp_options table.
Now remove any hooks in your theme that meddle with custom taxes and post types, and run this on init;
register_taxonomy(
'type',
'post',
array(
'hierarchical' => true,
'label' => 'Type',
'rewrite' => array('slug' => 'portfolio/type')
)
);
In your permalink settings, choose one of the default options, and make sure both a category and tag base is set, then update.
Dump $wp_rewrite as you did before, and you should see a few lines like so;
[portfolio/type/([^/]+)/page/?([0-9]{1,})/?$] => index.php?type=$matches[1]&paged=$matches[2]
[portfolio/type/([^/]+)/?$] => index.php?type=$matches[1]
These should be near the very beginning of the array, before tags, categories and the like.
Let me know how you get on!
(When I run the code in my install of WP 3.0-beta-2 it works, so I assume something funky is happening at the moment).
I'm sure you can fake a slug like that, using portfolio/type - the key is, once you've updated your code, you'll need to flush the rewrite rules.
Do this by simply re-saving your permalink settings in the admin.