1

Curious to know if anyone can provide a solution to the following...

I have 2 custom post types:

  1. Offers
    • Location (taxonomy)
  2. Businesses
    • Location (taxonomy)

I want to sort both offers and businesses by location but don't want to have to duplicate all the locations or add a new location to both custom post types. Is there a way for me to LINK the Businesses custom post type to the "Offers Location" taxonomy? I ask this because I don't want to have duplicated locations, unless this is not possible to accomplish.

1 Answer 1

3

I didn't know that I can register a taxonomy for more than 1 CPT/post type!

    register_taxonomy( 'location', array( 'offer', 'store' ), array(
        'label' => __( 'Location', 'themeify' ),
        'hierarchical' => true,
        'labels' => array(
            'name'                          => __( 'Location', 'themeify' ),
            'singular_name'                 => __( 'Location', 'themeify' ),
            'menu_name'                     => __( 'Location', 'themeify' ),
            'all_items'                     => __( 'All Locations', 'themeify' ),
            'edit_item'                     => __( 'Edit Location', 'themeify' ),
            'view_item'                     => __( 'View Location', 'themeify' ),
            'update_item'                   => __( 'Update Location', 'themeify' ),
            'add_new_item'                  => __( 'Add New Location', 'themeify' ),
            'new_item_name'                 => __( 'New Location Name', 'themeify' ),
            'parent_item'                   => __( 'Parent Location', 'themeify' ),
            'parent_item_colon'             => __( 'Parent Location:', 'themeify' ),
            'search_items'                  => __( 'Search Locations', 'themeify' ),
            'popular_items'                 => __( 'Popular Locations', 'themeify' ),
            'separate_items_with_commas'    => __( 'Separate locations with commas', 'themeify' ),
            'add_or_remove_items'           => __( 'Add or remove locations', 'themeify' ),
            'choose_from_most_used'         => __( 'Choose from the most used locations', 'themeify' ),
            'not_found'                     => __( 'No locations found', 'themeify' ),
        )

    ) );

I added the array with the custom post type 'offer' and 'store'.

Now, when I add a location to this taxonomy, it updates within BOTH offers and store :) No duplication of locations :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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