Viewing 4 reply threads
  • Author
    Posts
    • #3570
      s1r0n
      Member

      I’ve created many custom post types for wordpress now with Piklist, but can somebody tell me how to get “tags” added to the backend display so I can use tags as a taxonomy. i have managed to get categories to display, but not tags

    • #3571
      Steve
      Keymaster

      @s1r0n– Showing tags is the same as showing categories. However, the real name of tags, is post_tag. Make sure you are using that.

    • #11134
      xolotl
      Member

      I’m having trouble with what I think is the same need: to have a custom post type use the same stock tags taxonomy used by standard posts.

      Based on the documentation I’ve read, it seems like I only need to include the tags taxonomy when I register the custom post type (see below). It doesn’t seem like I need to register the existing tags taxonomy (ie, using “piklist_taxonomies”) also, as that seems to create yet another tags taxonomy in addition to the stock tags taxonomy.

      However, when I register the custom post type with the tags taxonomy, CPT posts don’t appear under the stock tags taxonomy archive.

      // Resources via Piklist: Add resource custom post type.
      add_filter(‘piklist_post_types’, ‘lm_resource_post_type’);
      function lm_resource_post_type($post_types) {
      $post_types[‘resource’] = array(
      ‘labels’ => piklist(‘post_type_labels’, ‘Resource’)
      ,’title’ => __(‘Enter a new resource 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(
      ‘author’
      ,’editor’
      ,’excerpt’
      ,’post_formats’
      ,’revisions’
      ,’thumbnail’
      ,’title’
      )
      ,’public’ => true
      ,’admin_body_class’ => array(
      ‘lm-resource-body-class’
      )
      ,’has_archive’ => true
      ,’rewrite’ => array(
      ‘slug’ => ‘resources’
      )
      ,’capability_type’ => ‘post’
      ,’edit_columns’ => array(
      ‘title’ => __(‘Resource’)
      ,’author’ => __(‘Contributed by’)
      )
      ,’taxonomies’ => array(‘post_tag’)
      );
      return $post_types;
      }

    • #11135
      Steve
      Keymaster

      Sometimes that’s not enough for WordPress and you need to use register_taxonomy_for_object_type

      Here are the docs: https://developer.wordpress.org/reference/functions/register_taxonomy_for_object_type/

      This should work:

      function my_register_taxonomy_for_object_type() {
          register_taxonomy_for_object_type( 'post_tag', 'resource' );
      }
      add_action( 'init', 'my_register_taxonomy_for_object_type' );
    • #11137
      xolotl
      Member

      Thanks @sbruner, that did the trick!

      I’ll also note if one wants different types of posts to show up together in various listings (like for authors, archives, etc), one has to make that happen with something like:

      add_filter( ‘pre_get_posts’, ‘lm_archive_author’ );
      function lm_archive_author( $query ) {
      if ( ( !is_admin() && $query->is_main_query() ) && ( is_front_page() || is_tax() || is_author() || is_archive() ) ) {
      $query->set( ‘post_type’, [‘resource’, ‘post’] );
      return $query;
      }
      }

Viewing 4 reply threads
  • The topic ‘adding tags to custom post types’ is closed to new replies.