admin管理员组文章数量:1130349
I have a custom post type call question which have custom taxonomies which is called question-tags. These question tag further used for creating dynamic quiz. I want to restrict users to use question-tags created by them only. They cann't access tags created by others. How it is possible?
Just let me know how to make tags private for each user so they cann't use tags create by each other in front end forms
I have a custom post type call question which have custom taxonomies which is called question-tags. These question tag further used for creating dynamic quiz. I want to restrict users to use question-tags created by them only. They cann't access tags created by others. How it is possible?
Just let me know how to make tags private for each user so they cann't use tags create by each other in front end forms
Share Improve this question edited Dec 28, 2018 at 12:16 K.A asked Dec 28, 2018 at 12:00 K.AK.A 12 bronze badges 1- i didn't tried much thing, since i am new php. But i tired make id do by using code if ( is_user_logged_in() ): ` global $current_user; wp_get_current_user(); $author_query = array( 'posts_per_page' => '-1', 'author' => $current_user->ID, 'post_type'=>'question' );` This code is helpful for displaying current user's custom post, but didn't helped me in tags – K.A Commented Dec 29, 2018 at 9:37
1 Answer
Reset to default 0This is a possible way of doing this. Whenever a new term is created, you execute the following code.
This code saves the current user_id as the term author, which should allow you to filter by user_id when fetching terms.
add_action( 'created_term', 'filter_user_specific_term', 10, 3 );
function filter_user($term_id, $tt_id, $taxonomy){
if( $taxonomy == "my_custom_taxonomy"){
if (isset($term_id)) {
add_term_meta ($term_id, "author", get_current_user_id());
}
}
}
To get the term list, according to current user:
$terms = get_terms( array(
'taxonomy' => 'my_custom_taxonomy',
'meta_key' => 'author',
'meta_value' => get_current_user_id() ) );
I didn't test this code but should be a good start point for doing what you want.
I have a custom post type call question which have custom taxonomies which is called question-tags. These question tag further used for creating dynamic quiz. I want to restrict users to use question-tags created by them only. They cann't access tags created by others. How it is possible?
Just let me know how to make tags private for each user so they cann't use tags create by each other in front end forms
I have a custom post type call question which have custom taxonomies which is called question-tags. These question tag further used for creating dynamic quiz. I want to restrict users to use question-tags created by them only. They cann't access tags created by others. How it is possible?
Just let me know how to make tags private for each user so they cann't use tags create by each other in front end forms
Share Improve this question edited Dec 28, 2018 at 12:16 K.A asked Dec 28, 2018 at 12:00 K.AK.A 12 bronze badges 1- i didn't tried much thing, since i am new php. But i tired make id do by using code if ( is_user_logged_in() ): ` global $current_user; wp_get_current_user(); $author_query = array( 'posts_per_page' => '-1', 'author' => $current_user->ID, 'post_type'=>'question' );` This code is helpful for displaying current user's custom post, but didn't helped me in tags – K.A Commented Dec 29, 2018 at 9:37
1 Answer
Reset to default 0This is a possible way of doing this. Whenever a new term is created, you execute the following code.
This code saves the current user_id as the term author, which should allow you to filter by user_id when fetching terms.
add_action( 'created_term', 'filter_user_specific_term', 10, 3 );
function filter_user($term_id, $tt_id, $taxonomy){
if( $taxonomy == "my_custom_taxonomy"){
if (isset($term_id)) {
add_term_meta ($term_id, "author", get_current_user_id());
}
}
}
To get the term list, according to current user:
$terms = get_terms( array(
'taxonomy' => 'my_custom_taxonomy',
'meta_key' => 'author',
'meta_value' => get_current_user_id() ) );
I didn't test this code but should be a good start point for doing what you want.
本文标签: custom taxonomyFilter Tags for current users
版权声明:本文标题:custom taxonomy - Filter Tags for current users 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749058595a2309746.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论