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
Add a comment  | 

1 Answer 1

Reset to default 0

This 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
Add a comment  | 

1 Answer 1

Reset to default 0

This 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