Viewing 13 reply threads
  • Author
    Posts
    • #10683
      guit4eva
      Participant

      Hello again,

      I’m trying to get a custom taxonomy to show on a custom post type, but I can’t get it to display properly. This is my code so far:

          $post_types['package'] = array(
              'labels' => piklist('post_type_labels', 'Packages')
              , 'title' => __('Enter a new Package Title')
              , 'supports' => array(
                  'title'
                  , 'editor'
                  , 'post-formats'
                  , 'thumbnail',
              )
              , 'public' => true
              , 'admin_body_class' => array(
                  'custom-body-class',
              )
              , 'has_archive' => true
              , 'rewrite' => array(
                  'slug' => 'package',
              )
              , 'capability_type' => 'post'
              , 'hide_meta_box' => array(
                  'author',
              ),
          );
          return $post_types;
      }
      
      add_filter('piklist_taxonomies', 'package_tax');
      function package_type_tax($taxonomies) {
         $taxonomies[] = array(
            'post_type' => 'package'
            ,'name' => 'package_type'
            ,'show_admin_column' => true
            ,'configuration' => array(
              'hierarchical' => false
              ,'labels' => piklist('taxonomy_labels', 'Package Type')
              ,'hide_meta_box' => true
              ,'show_ui' => true
              ,'query_var' => true
              ,'rewrite' => array(
                'slug' => 'package-type'
              )
            )
          );
        return $taxonomies;
      }

      If anyone can tell me where I’m going wrong, I’d really appreciate that!

    • #10684
      Steve
      Keymaster

      Your function is package_type_tax, but the filter is calling package_tax. They need to match.

    • #10685
      guit4eva
      Participant

      I don’t know what’s greater: the speed at which you replied or my embarrassment for such a silly mistake ha ha…

      Thanks for that, however the issue still persists after correction:

      add_filter('piklist_taxonomies', 'package_type_tax');
      function package_type_tax($taxonomies) {

      Not sure what else I’m doing wrong?

    • #10686
      Steve
      Keymaster

      Ha! Thank you.

      So, your code works for me when I use the default post cpt. Try changing 'post_type' => 'package' to 'post_type' => 'post' and see if that works. If so, there may be something going on with your cpt registration.

    • #10687
      guit4eva
      Participant

      Drats, no luck… I’ve tried 'post_type' => 'post', checked Screen Options, nothing is showing in my cpt or in the default posts screen. Really stumped on this one!

    • #10688
      Steve
      Keymaster

      what file is this in? And what is the path?

      add_filter('piklist_taxonomies', 'package_type_tax');
      function package_type_tax($taxonomies) { ...
    • #10689
      guit4eva
      Participant

      It’s in /wp-content/plugins/custom-pklist/custom.php. This is the full file:

      <?php
      
      /**
       * Plugin Name: Custom Piklist Functions
       * Description: Custom Piklist Functions
       * Author: SS
       * Version: 0.1
       * Plugin Type: Piklist
       */
      
      add_filter('piklist_post_types', 'piklist_custom_post_types');
      function piklist_custom_post_types($post_types)
      {
      
          $post_types['event'] = array(
              'labels' => piklist('post_type_labels', 'Events')
              , 'title' => __('Enter a new Event Title')
              // ,'menu_icon' => piklist('url', 'piklist') . '/parts/img/piklist-menu-icon.svg'
              // ,'page_icon' => piklist('url', 'piklist') . '/parts/img/piklist-page-icon-32.png'
              , 'supports' => array(
                  'title'
                  , 'editor'
                  , 'post-formats'
                  , 'thumbnail',
              )
              , 'public' => true
              , 'admin_body_class' => array(
                  'custom-body-class',
              )
              , 'has_archive' => true
              , 'rewrite' => array(
                  'slug' => 'event',
              )
              , 'capability_type' => 'post'
              // ,'edit_columns' => array(
              //   'title' => __('Demo')
              //   ,'author' => __('Assigned to')
              // )
              , 'hide_meta_box' => array(
                  'author',
              ),
              // ,'status' => array(
              //   'new' => array(
              //     'label' => 'New'
              //     ,'public' => false
              //   )
              //   ,'pending' => array(
              //     'label' => 'Pending Review'
              //     ,'public' => false
              //   )
              //   ,'demo' => array(
              //     'label' => 'Demo'
              //     ,'public' => true
              //     ,'exclude_from_search' => true
              //     ,'show_in_admin_all_list' => true
              //     ,'show_in_admin_status_list' => true
              //  )
              //   ,'lock' => array(
              //     'label' => 'Lock'
              //     ,'public' => true
              //   )
              // )
          );
      
          $post_types['package'] = array(
              'labels' => piklist('post_type_labels', 'Packages')
              , 'title' => __('Enter a new Package Title')
              // ,'menu_icon' => piklist('url', 'piklist') . '/parts/img/piklist-menu-icon.svg'
              // ,'page_icon' => piklist('url', 'piklist') . '/parts/img/piklist-page-icon-32.png'
              , 'supports' => array(
                  'title'
                  , 'editor'
                  , 'post-formats'
                  , 'thumbnail',
              )
              , 'public' => true
              , 'admin_body_class' => array(
                  'custom-body-class',
              )
              , 'has_archive' => true
              , 'rewrite' => array(
                  'slug' => 'package',
              )
              , 'capability_type' => 'post'
              // ,'edit_columns' => array(
              //   'title' => __('Demo')
              //   ,'author' => __('Assigned to')
              // )
              , 'hide_meta_box' => array(
                  'author',
              ),
              // ,'status' => array(
              //   'new' => array(
              //     'label' => 'New'
              //     ,'public' => false
              //   )
              //   ,'pending' => array(
              //     'label' => 'Pending Review'
              //     ,'public' => false
              //   )
              //   ,'demo' => array(
              //     'label' => 'Demo'
              //     ,'public' => true
              //     ,'exclude_from_search' => true
              //     ,'show_in_admin_all_list' => true
              //     ,'show_in_admin_status_list' => true
              //  )
              //   ,'lock' => array(
              //     'label' => 'Lock'
              //     ,'public' => true
              //   )
              // )
          );
          return $post_types;
      }
      
      add_filter('piklist_taxonomies', 'package_type_tax');
      function package_type_tax($taxonomies) {
         $taxonomies[] = array(
            'post_type' => 'package'
            ,'name' => 'package_type'
            ,'show_admin_column' => true
            ,'configuration' => array(
              'hierarchical' => false
              ,'labels' => piklist('taxonomy_labels', 'Package Type')
              ,'hide_meta_box' => true
              ,'show_ui' => true
              ,'query_var' => true
              ,'rewrite' => array(
                'slug' => 'package-type'
              )
            )
          );
        return $taxonomies;
      }
    • #10690
      Steve
      Keymaster

      Your code works for me. I just placed it in my themes functions.php file: https://cloudup.com/cTlwcEicwDk

      Make sure the plugin is activated.

    • #10691
      guit4eva
      Participant

      Hi there Steve,

      Thanks so much for your assistance. I discovered that I still needed to add the following to my parts file:

      piklist('field', array(
        'type' => 'select'
        ,'scope' => 'taxonomy'
        ,'field' => 'category'
        ,'label' => 'Categories'
        ,'description' => 'Terms will appear when they are added to this taxonomy.'
        ,'choices' => array(
            '' => 'Choose Term'
          )
          + piklist(get_terms(array(
            'taxonomy' => 'package_type'
            ,'hide_empty' => false
          ))
          ,array(
            'term_id'
            ,'name'
          )
        )
      ));

      I was expecting the taxonomy section to show up in the right sidebar, which was what threw me off. It’s all working correctly now though 🙂

      Thanks so much again for your help, it’s greatly appreciated!!

    • #10692
      Steve
      Keymaster

      Ah… The reason the metabox wasn’t showing up is because you have this Piklist parameter set ,'hide_meta_box' => true, which hides the meta box: https://docs.piklist.com/actions-filters/filters/piklist_taxonomies/#hide_meta_box

    • #10693
      guit4eva
      Participant

      Ah ok! 🙂 I see it’s showing up now in the sidebar – yesss!! What is the difference though with that, and then adding them as I did in the previous post (piklist(‘field’, array(‘type’ => ‘select’…)? I see if I add a duplicate taxonomy to the taxonomy field in the right sidebar, it doesn’t reflect in the taxonomy selection in the Piklist main section – although I’d think they’d be the same thing?…I’ll add a picture to explain what I mean:

      Taxonomy

      Sorry if that’s a silly question, just trying to understand how this all fits together.

    • #10694
      Steve
      Keymaster

      The reason you would include 'hide_meta_box' => true and create your own Piklist field for your taxonomy is if you didn’t want to use the default WordPress UI for your Taxonomy terms.

      You could use Chosen or Select2 to add some cool functionality.

      Instead of checkboxes you could use Radio Buttons or a Select field.

      Or maybe you want to group your taxonomy terms by their parent.

      With Piklist you don’t have to limit yourself to the default WordPress UI. You can easily change it, and still save your data normally.

    • #10695
      guit4eva
      Participant

      Ah, ok! Yes, I see how that could be very useful – especially if combining with something like Chosen. Piklist is really such a good addition to WordPress, really keen to learn about everything it can do 🙂

      Thanks once again for your absolute stellar support!!!

      Have a fantastic week 🙂

    • #10696
      Steve
      Keymaster

      If you have the time, feel free to leave a review on WordPress.org. It really helps the project. Thanks!

Viewing 13 reply threads
  • The topic ‘Taxonomies not showing’ is closed to new replies.