This topic contains 8 replies, has 2 voices, and was last updated by  Steve 1 year, 1 month ago.

  • Author
    Posts
  • #9016

    achowell
    Participant

    So I followed the tutorial to set up a selection box that has my custom taxonomy values, but its not appearing for some reason. The taxonomy is Project Status and the options I added are Open and Close.

    Here is the code used to create the taxonomy and hide the original metabox

    //Create Project Status Taxonomy
    add_filter('piklist_taxonomies', 'project_status');
      function project_status($taxonomies) {
         $taxonomies[] = array(
            'post_type' => 'mro_project'
            ,'name' => 'project_status'
            ,'show_admin_column' => true
            ,'configuration' => array(
              'hierarchical' => true
              ,'labels' => piklist('taxonomy_labels', 'Project State')
              ,'hide_meta_box' => true
              ,'show_ui' => true
              ,'query_var' => true
              ,'rewrite' => array(
                'slug' => 'project-status'
              )
            )
          );
        return $taxonomies;
      }

    Here is what is in the file for the selection/dropdown version that is not appearing. This is the only thing in the php file, exactly as is and is located in parts/terms.

    piklist('field', array(
      'type' => 'select'
      ,'scope' => 'taxonomy'
      ,'field' => 'project_status'
      ,'label' => 'Project Status'
      ,'description' => 'Change status of project based on amount of people registered'
      ,'choices' => array(
          '' => 'Open'
        )
        + piklist(get_terms(array(
          'taxonomy' => 'project_status'
          ,'hide_empty' => false
        ))
        ,array(
          'term_id'
          ,'name'
        )
      )
    ));
  • #9020

    achowell
    Participant

    Changed it to the below in the terms folder and still have nothing showing up:

    Title: Project Status
    Description: Change status of project depending on whtether the maximum number of volunteers has been reached.
    Taxonomy: project_status
    Capability: manage_options
    Order: 0
    */
    
    piklist('field', array(
    'type' => 'select'
    ,'scope' => 'taxonomy'
    ,'field' => 'mro_project_status'
    ,'label' => 'Project Status'
    ,'description' => 'Change status of project based on amount of people registered'
    ,'choices' => piklist(get_terms('project_status', array(
    'hide_empty' => false,
    ))
    , array(
    'term_id'
    , 'name',
    )
    ),
    ));
  • #9021

    Steve
    Keymaster

    @achowell– if I change 'post_type' => 'mro_project' to 'post_type' => 'post' you code works for me. So, two things to look at:

    1) Is the CPT mro_project registered?
    2) Where are the folders parts/terms/ located?

  • #9022

    achowell
    Participant

    Hello Steve, thanks for the reply, the parts/terms is in the plugin, this plugin also creates the mro_project post type through the piklist method. I made some edits to the field code and moved it into the meta box section and it works there. I’m not sure why its not working in the terms folder, but using it in the meta box will work for me, though its now giving me this warning.

    Warning: array_column() expects parameter 1 to be array, object given in <plugin_path>/piklist/includes/class-piklist.php on line 2524

  • #9027

    Steve
    Keymaster

    If you create a term and edit it, is the field there?

    • #9028

      achowell
      Participant

      Okay, I was looking for it in the wrong place! Sorry, so I missunderstoopd where this was located. It seems what I wanted was my second solution. A meta-box in the edit section of the post type. I did eventually get the taxonomy drop down on the custom post type edit page, but it does not save on update and it still has that warning message in the meta box.

      Warning: array_column() expects parameter 1 to be array, object given in <plugin_path>/piklist/includes/class-piklist.php on line 2524

  • #9029

    achowell
    Participant

    Thanks for the help Steve, I removed scope from the code and that solved all of the issues. One last question and you can close this one, how do I set a default selection for the taxonomy dropdown?

  • #9030

    Steve
    Keymaster

    Great. Glad you got it working.

    Use the value parameter to set the default:
    https://docs.piklist.com/fields/field-parameters/

  • #9038

    Steve
    Keymaster

    Closing this ticket.

The topic ‘Custom Taxonomy Select Box Missing in Editor’ is closed to new replies.