• Hi, I have a website where I publish projects which are assigned with some custom fields. I use these fields: Type of the project, Status, Material, Location, Date and some more. I want them to act like categories – when I click on the value (for example Wood for the Material field) I want it to show me all the post categorized under “Wood”.

    Should I use categories for this and display them in different parent groups that I mentioned (too many categories for one post?) or should I use custom fields (they are not clickable).

    Example:

    Country: Austria
    Year: 2006
    Material: Wood
    Status: Built

    Thanks 😉

Viewing 6 replies - 1 through 6 (of 6 total)
  • I’d set them up as custom taxonomies and attach them to the post type that you’re using for the projects. That way they’re all set up the same was as categories, and will all have archive pages available in the same way.

    Thread Starter Perotin

    (@perotin)

    Thanks. Can I have both categories and custom taxonomies in a post? I use the default post type.

    Taxonomies are a form of categories, why don’t you just do the whole structure in your custom taxonomy.

    As potentdevelopment said, Categories are just a Taxonomy, and you can add extra taxonomies to any post type that you like, as well as adding as many as you like to the standard post type(s). As an example…

    register_taxonomy( 'country', 'post', array ('label' => 'Country') );

    You can create non-hierarchal tag-like custom taxonomies for each field.
    Country, Year, Material, Status.
    Then, you can pre-populate within your theme’s functions.php file the most common fields to be ready for use.
    As a rule of thumb I tend to use Taxonomies when I want to group posts by a specific criteria.
    And custom fields when I want to sort or filter a certain post-type by these fields.
    I think in your case, using custom-taxonomies would be the way to go.
    You’l benefit from their built-in url structure and ease of use.
    Furthermore, in the future if you’l want to filter by multiple taxonomies, for example:
    Projects in Australia built with Wood in 2006.
    It would be easy to implement if you used taxonomies.

    Thread Starter Perotin

    (@perotin)

    wow, thanks. it works. I used this code to register the custom taxonomy

    add_action( 'init', 'create_material_taxonomy' );
    
    function create_material_taxonomy() {
    	$labels = array(
    		'name'                           => 'Materials',
    		'singular_name'                  => 'Material',
    		'search_items'                   => 'Search Materials',
    		'all_items'                      => 'All Materials',
    		'edit_item'                      => 'Edit Material',
    		'update_item'                    => 'Update Material',
    		'add_new_item'                   => 'Add New Material',
    		'new_item_name'                  => 'New Material Name',
    		'menu_name'                      => 'Material',
    		'view_item'                      => 'View Material',
    		'popular_items'                  => 'Popular Materials',
    		'separate_items_with_commas'     => 'Separate materials with commas',
    		'add_or_remove_items'            => 'Add or remove materials',
    		'choose_from_most_used'          => 'Choose from the most used materials',
    		'not_found'                      => 'No materials found'
    	);
    
    	register_taxonomy(
    		'materials',
    		'post',
    		array(
    			'label' => __( 'Material' ),
    			'hierarchical' => true,
    			'labels' => $labels,
    			'public' => true,
    			'show_in_nav_menus' => true,
    			'show_tagcloud' => false,
    			'show_admin_column' => true,
    			'rewrite' => array(
    				'slug' => 'materials'
    			)
    		)
    	);
    }

    I have also installed this plugin to filter multiple taxonomies: https://wordpress.org/plugins/search-filter

    thank you very much! 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Categories or custom fields?’ is closed to new replies.