Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Doan Manh Duc

    (@duc88b)

    Hi soumali! currently, this plugin doesn’t support to add terms ( categories, tags, custom taxonomies ) but we will do it in next version. Thank you for your question.

    I am looking for the same thing.

    The last update (Dec 25th) did not have support for adding terms.

    When will the next update be released?

    Could I help with adding this support?

    So I’m close to a solution without modifying the plugin.

    If you add the following code to your theme’s functions.php, a new meta beta will appear when creating a custom post type:

    function cpt_support_for_cats_and_tags_meta_boxes( $meta_boxes ) {
    	// Taxonomies
    	$args_prefix  = 'args_';
    	$meta_boxes[] = array(
    		'id'       => 'taxonomies',
    		'title'    => __( 'Supports Categories/Tags', 'mb-custom-post-type' ),
    		'pages'    => array( 'mb-post-type' ),
    		'priority' => 'low',
    		'context'  => 'side',
    		'fields'   => array(
    			array(
    				'id'      => $args_prefix . 'taxonomies',
    				'type'    => 'checkbox_list',
    				'options' => array(
    					'category' => __( 'Categories', 'mb-custom-post-type' ),
    					'post_tag' => __( 'Tags', 'mb-custom-post-type' ),
    				),
    			),
    		),
    	);
    	return $meta_boxes;
    }
    add_filter( 'rwmb_meta_boxes', 'cpt_support_for_cats_and_tags_meta_boxes' );

    The catch is that you have to select BOTH categories AND tags.

    This is because of line 87 in \inc\post-type\register.php
    $data = 1 == count( $value ) ? $value[0] : $value;

    When you check only one of the check boxes either categories or tags, the count() of the array for taxonomies is 1 and $data becomes either ‘category’ or ‘post_tag’. Then when the post type is registered on line 57, $args['taxonomies'] is not an array like it is expecting

    I will keep working and see if I can come up with some code to edit the plugin with that will give the correct result.

    rilwis has released a new version of the code that adds support for the WordPress predefined taxonomies Category and Tags.

    However, there is still an issue with line 87 (89 in the new version) in \inc\post-type\register.php
    $data = 1 == count( $value ) ? $value[0] : $value;

    Here is some code to fix the issue.

    Replace this:
    $data = 1 == count( $value ) ? $value[0] : $value;
    With this:

    if ($key != 'args_taxonomies' )
        $data = 1 == count( $value ) ? $value[0] : $value;
    else
        $data = $value;

    This will probably be incorporated into the next version of the plugin.

    frank6

    (@frank6)

    Seems like it is working out of the box now. Except that if we want to access the custom post list from the category page (archive.php), we need to add the custom type to the wp_query.

    // Took from : http://premium.wpmudev.org/blog/add-custom-post-types-to-tags-and-categories-in-wordpress/
    function add_custom_types_to_tax( $query ) {
    if( is_category() || is_tag() && empty( $query->query_vars[‘suppress_filters’] ) ) {
    // Get all your post types
    $post_types = get_post_types();

    $query->set( ‘post_type’, $post_types );
    return $query;
    }
    }
    add_filter( ‘pre_get_posts’, ‘add_custom_types_to_tax’ );

    It would be great if we don’t have to add manually the custom_post type to the query.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘categories support’ is closed to new replies.