0

I know this question has probably been asked many times but I have tried googling without any success (at least without using a plugin)

I have a custom post type for "Publishers" which contains all the details of each publisher. When I write a blog post I would like to have a taxonomy pre-populated with all the publishers and preferable only allow existing publishers to be entered.

Then on each publishers page I want to a do a WP-Query using the slug or ID (for that publisher) to find all posts tagged with the publisher (some posts discuss multiple publishers).

I know that there are plugins that allow me to do this and much more and that I could assign the same tag to both a publisher and post but I want avoid a situation where I have to tag in both ends. As soon as a publisher is saved with a slug and title I want to be able to tag a post with that.

I'm not looking for the exact code to do this but rather the layout / structure to achieve this in the simplest way possible.

-1

Very Simple Code Snippet for Creating Taxonomy for Custom Post Type

Register Custom Post Type

function Knowledge_base_init() {
$labels = array(
    'name'               => _x( 'Knowledge bases', 'post type general name', 'your-plugin-textdomain' ),
    'singular_name'      => _x( 'Knowledge base', 'post type singular name', 'your-plugin-textdomain' ),
    'menu_name'          => _x( 'Knowledge bases', 'admin menu', 'your-plugin-textdomain' ),
    'name_admin_bar'     => _x( 'Knowledge base', 'add new on admin bar', 'your-plugin-textdomain' ),
    'add_new'            => _x( 'Add New', 'Knowledge base', 'your-plugin-textdomain' ),
    'add_new_item'       => __( 'Add New Knowledge base', 'your-plugin-textdomain' ),
    'new_item'           => __( 'New Knowledge base', 'your-plugin-textdomain' ),
    'edit_item'          => __( 'Edit Knowledge base', 'your-plugin-textdomain' ),
    'view_item'          => __( 'View Knowledge base', 'your-plugin-textdomain' ),
    'all_items'          => __( 'All Knowledge bases', 'your-plugin-textdomain' ),
    'search_items'       => __( 'Search Knowledge bases', 'your-plugin-textdomain' ),
    'parent_item_colon'  => __( 'Parent Knowledge bases:', 'your-plugin-textdomain' ),
    'not_found'          => __( 'No Knowledge bases found.', 'your-plugin-textdomain' ),
    'not_found_in_trash' => __( 'No Knowledge bases found in Trash.', 'your-plugin-textdomain' )
);

$args = array(
    'labels'             => $labels,
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => true,
    'query_var'          => true,
    'rewrite'            => array( 'slug' => 'Knowledge_base' ),
    'capability_type'    => 'post',
    'has_archive'        => true,
    'hierarchical'       => false,
    'menu_position'      => null,
    'menu_icon' => admin_url() . 'images/media-button-video.gif',
    'supports'           => array( 'title', 'editor', 'author')
);

register_post_type( 'knowledge-base', $args );
}


add_action( 'init', 'create_knowledge_base_taxonomies', 0 );
function create_knowledge_base_taxonomies() {
// Add Tips taxonomies
$labels = array(
    'name'              => _x( 'Tips & Tricks', 'taxonomy general name' ),
    'singular_name'     => _x( 'Tips & Tricks', 'taxonomy singular name' ),
    'search_items'      => __( 'Search Tips & Tricks' ),
    'all_items'         => __( 'All Tips & Tricks' ),
    'parent_item'       => __( 'Parent Tips & Tricks' ),
    'parent_item_colon' => __( 'Parent Tips & Tricks:' ),
    'edit_item'         => __( 'Edit Tips & Tricks' ),
    'update_item'       => __( 'Update Tips & Tricks' ),
    'add_new_item'      => __( 'Add New Tips & Tricks' ),
    'new_item_name'     => __( 'New Tips & Tricks Name' ),
    'menu_name'         => __( 'Tips & Tricks' ),
);

$args = array(
    'hierarchical'      => true,
    'labels'            => $labels,
    'show_ui'           => true,
    'show_admin_column' => true,
    'query_var'         => true,
    'rewrite'           => array( 'slug' => 'tips' ),
);

register_taxonomy( 'tips', array( 'knowledge-base' ), $args );
}

That help you for creating taxonomy.

  • 2
    The link is broken for me. Also in general lone link is considered a poor answer (see help > deleted answers) since it is meaningless by itself and target resource is not guaranteed to be alive in the future. Please try to include at least summary of information you are linking to. – Rarst Dec 9 '14 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.