• Hi,
    I wanting to only show category markers from a specific parent. My store categories (parent and child) are as follows:
    Fuel Stations
    – BP
    – Shell
    – etc
    Loyalty
    – ebucks
    – vitality
    – etc
    For example if a store has a category of Shell AND ebucks, then only get the marker from the Fuel Stations parent (ID of 12).

    So far I am using this but not having any succes.

    function mytank_custom_store_category_image( $store_meta, $store_id ) {
    
        if ( function_exists( 'z_taxonomy_image_url' ) ) {
            $terms = wp_get_post_terms( $store_id, 'wpsl_store_category' );
    
            if ( $terms ) {
                if ( !is_wp_error( $terms ) ) {
                    if ( isset( $_GET['filter'] ) && $_GET['filter'] ) {
                        $filter_ids = explode( ',', $_GET['filter'] );
    
                        foreach ( $terms as $term ) {
                            //only return terms whose parent is Fuel Stations (ID)
                            if ($term->parent == 12){ 
    
                                if ( in_array( $term->term_id, $filter_ids ) ) {
                                    $cat_marker = z_taxonomy_image_url( $term->term_id );
    
                                    if ( $cat_marker ) {
                                        $store_meta['categoryMarkerUrl'] = $cat_marker;
                                    }
                                }
                            }
                        }
                    } else {
                        $store_meta['categoryMarkerUrl'] = z_taxonomy_image_url( $terms[0]->term_id );
                    }
                }
            }
        }
    
        return $store_meta;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter southafricanrob

    (@southafricanrob)

    Apologies – I just found a simple solution – here it is in case of use to someone else:

    Simply use
    $terms = wp_get_post_terms( $store_id, 'wpsl_store_category', array( 'parent' => 12 ) );

    which will only populate the array of terms from the parent category/s specified, in my case parent with ID = 12.

    Hi, thanks for finding a workaround!

    Bear in mind that you can also restrict the categories shown in the map by using the parameter “category” in the [wpsl] shortcode, although I don’t know if that is exactly what you wanted.

    Regards,

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Only show custom categories marker from a specific parent’ is closed to new replies.