- This topic has 7 replies, 2 voices, and was last updated 6 years, 1 month ago by
Steve.
-
AuthorPosts
-
-
December 22, 2015 at 10:56 am #5407
friendlyfire3MemberI have this in my piklist plugin
add_filter('piklist_taxonomies', 'test_tax'); function test_tax($taxonomies){ $taxonomies[] = array( 'post_type' => array('post','page', 'user') // multiple CPTs and Users? ,'name' => 'testtax' ,'show_admin_column' => true ,'configuration' => array( 'hierarchical' => true ,'labels' => piklist('taxonomy_labels', 'testtax') ,'hide_meta_box' => false ,'show_ui' => true ,'query_var' => true ) ); return $taxonomies; }Thought it might work since I know they can be registered on users but it doesn’t.
I saw this tutorial on registering a tax when a user logged in but it’s not really what I need. I just want to be able to assign terms from across different post types to a user too.
Any ideas?
-
December 22, 2015 at 12:34 pm #5410
SteveKeymasterThis is done in the Piklist Demos so you can use that as a reference. You need to set
object_type.'object_type' => 'user'
Taxonomies can’t be registered for users and Post Types. Once you register the taxonomy you can assign it to Posts and Pages using the standard WordPress function
register_taxonomy_for_object_type()
`function my_register_taxonomy_for_cpts() { register_taxonomy_for_object_type('testtax', 'post'); register_taxonomy_for_object_type('testtax', 'page'); } add_action('init', 'my_register_taxonomy_for_cpts'); -
December 22, 2015 at 2:20 pm #5411
friendlyfire3MemberThanks, Steve.
I’m now following this:https://piklist.com/user-guide/tutorials/display-taxonomies-as-a-dropdown-or-radio-buttons/
but i’m placing the below in the /users folder and an referencing the test_tax (from the example in my first post) via get_terms. I see the meta-box and field but am not seeing the terms come back on the user’s profile (even though they do exist).
<?php /* Title: My User Metabox Description: My cool new metabox Taxonomy: testtax Capability: manage_options */ piklist('field', array( 'type' => 'select' ,'scope' => 'taxonomy' ,'field' => 'testtax' ,'label' => 'Test Tax' ,'description' => 'Terms will appear when they are added to this taxonomy.' ,'choices' => array( '' => 'Choose Term' ) + piklist(get_terms('test_tax', array( 'hide_empty' => false )) ,array( 'term_id' ,'name' ) ) ));Any suggestions?
-
December 22, 2015 at 2:28 pm #5412
SteveKeymasterIt’s working for me.
When you click on ALL USERS in the left menu, is your taxonomy listed in the sub menu?
-
December 22, 2015 at 2:31 pm #5413
friendlyfire3MemberYes, the taxonomy does show in the users menu list.
I am registering the taxonomy in a standalone piklist plugin and putting the user metabox stuff in my theme. Does that matter?
-
December 22, 2015 at 2:33 pm #5414
SteveKeymasterNo. Should be fine. Working for me. Try pulling at the get_terms() function and making it work. Once you get it to work you can put it back into your field.
-
December 22, 2015 at 3:41 pm #5415
friendlyfire3MemberGot it working. I had to tamper with the settings a bit. I had some things missnamed.
Thanks!
-
December 22, 2015 at 10:25 pm #5418
SteveKeymasterGreat! Closing ticket.
-
-
AuthorPosts
- The topic ‘Register Taxonomy for a user via piklist’ is closed to new replies.