• Resolved owhited

    (@owhited)


    I have a multi-user blog. When a user, say user4 is created, I use user_register and wp_create_term to automatically create the category term ‘user4’.

    Now I want this: When user4 creates a post, I want him to have the ability to see and assign only ‘user4’ and its child terms, to the post he creates.

    How can I do it using custom code?

    • This topic was modified 5 years, 1 month ago by owhited.
Viewing 3 replies - 16 through 18 (of 18 total)
  • Thread Starter owhited

    (@owhited)

    The remove_filter() function works as intended.

    From the docs it appears that wp_unique_term_slug() can only be used on a term that is already created. To make it’s slug unique across taxonomies.

    What if I want to make a slug unique before creating it, when I have only the term name? My users have no idea of what a slug is and they’ll leave the slug empty while creating a term. They are going to give me only the term name.

    • This reply was modified 5 years, 1 month ago by owhited.
    Thread Starter owhited

    (@owhited)

    I manually implemented the generation of a unique slug using get_term_by() function. It works. Thank you @bcworkz for your patient help. ??

    $unique_slug = $term;  # pre_insert_term hook gives $term
    $i = 1;
    $term_obj = get_term_by( 'slug', $unique_slug, $taxonomy);
    	while ( $term_obj ) {
    		$unique_slug = $term . $i;
    		$i++;
    		$term_obj = get_term_by( 'slug', $unique_slug, $taxonomy);
    	}
    	
    $term_data['slug'] = $unique_slug;
    • This reply was modified 5 years, 1 month ago by owhited.
    Moderator bcworkz

    (@bcworkz)

    You’re welcome. Nicely done!

    It turns out wp_unique_term_slug() isn’t for the purpose I was hoping it was for. One might question why we need an existing term in order to use the function when terms cannot be inserted without unique slugs. Answer: Redundant slugs among different taxonomies used to be allowed. The function was used to upgrade DBs that had redundant slugs so that all terms have unique slugs. I wish I realized this before trying to suggest it here.

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘Show a specific category and its children to a user when he creates post’ is closed to new replies.