Viewing 7 reply threads
  • Author
    Posts
    • #5407

      I 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?

    • #5410
      Steve
      Keymaster

      This 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');
      
    • #5411

      Thanks, 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?

    • #5412
      Steve
      Keymaster

      It’s working for me.

      When you click on ALL USERS in the left menu, is your taxonomy listed in the sub menu?

    • #5413

      Yes, 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?

    • #5414
      Steve
      Keymaster

      No. 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.

    • #5415

      Got it working. I had to tamper with the settings a bit. I had some things missnamed.

      Thanks!

    • #5418
      Steve
      Keymaster

      Great! Closing ticket.

Viewing 7 reply threads
  • The topic ‘Register Taxonomy for a user via piklist’ is closed to new replies.