Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Tijmen Smit

    (@tijmensmit)

    Not without making several modifications to the core files, sorry. This will be much easier in a future update.

    It’s to much to write out all the steps in detail, but in short it comes down to this.

    You would have to register the custom taxonomy with something like this ( you can add this in the functions.php in your theme folder ).

    add_action( 'init', 'wpsl_register_taxonomies', 10, 1 );
    
    function wpsl_register_taxonomies() {
    
        $args = array(
            'hierarchical'          => true,
            'show_ui'               => true,
            'show_admin_column'     => true,
            'update_count_callback' => '_update_post_term_count',
            'query_var'             => true,
        );
    
        register_taxonomy( 'wpsl_custom_category', 'wpsl_stores', $args );
    }

    Include the new dropdown in a custom template, you can load it for example from your theme folder with this filter.

    Add the extra category filter values in the ajax request made in the function makeAjaxRequest in the /js/wpsl-gmap.js file ( the wpsl-gmap.min.js is loaded, so you will have to minify it first, or enable script_debug to make it load non minified files ). Then modify the sql query in the ‘find_nearby_locations’ function in the class-frontend to include the values in the search.

    So, it’s possible but you have to modify quite a bit to make it work.

    I will make things much easier in a future update. I’m planning to make the ajax request always include the values from all detected dropdowns, so you can add as many as you want, and also adjust the sql so that it can take more then one term id.

    Thread Starter rrfranco92

    (@rrfranco92)

    Hey

    Thank you so much for your help.

    I’ve managed to get the second taxonomy just my adding your code to functions.php, adding a new function create category filter in class-frontend.php and then adding it to my own template and it is displaying.

    Will it still work like this?

    Plugin Author Tijmen Smit

    (@tijmensmit)

    It should work, but you do need to make sure you use a unique ID on both your dropdowns, use that ID in the makeAjaxRequest in the /js/wpsl-gmap.js file to grab the correct dropdown value.

    You can check if this happens correctly by looking at the ajax parameters in the browser console. In Firefox you can access this by ctrl+shift+i, then go to the network tab, select xhr at the bottom and make a search.

    Click on the request, in the right side click on ‘params’ and see if the values are there. If not something is wrong with your jQuery code.

    The next step is to use it in the sql query. But I don’t have time to write out the exact code.

    Thread Starter rrfranco92

    (@rrfranco92)

    Hey Tijmen,
    You’ve been very helpful, really!

    I added the following code to the wpsl-map.js with a unique ID

    if ( $( "#wpsl-custom-category" ).length > 0 ) {
    			if ( isMobile ) {
    				customcategoryId = parseInt( $( "#wpsl-custom-category .wpsl-dropdown" ).val() );
    			} else {
    				customcategoryId = parseInt( $( "#wpsl-custom-category .wpsl-selected-item" ).attr( "data-value" ) );
    			}
    
    			if ( ( !isNaN( customcategoryId ) && ( customcategoryId !== 0 ) ) )  {
    				ajaxData.filter = customcategoryId;
    			}
    		}

    I changed a few variables name so it doesn’t repeat in the same function.

    I’m now trying to add the sql query but I don’t no much about it and I’m also asking for help in other forums.

    I guess this is the SQL query code, and I tried adding
    the

    AND term_tax.taxonomy = ‘wpsl_custom_category’

    but it doesn’t work.

    ` $cat_filter = “INNER JOIN $wpdb->term_relationships AS term_rel ON posts.ID = term_rel.object_id
    INNER JOIN $wpdb->term_taxonomy AS term_tax ON term_rel.term_taxonomy_id = term_tax.term_taxonomy_id
    AND term_tax.taxonomy = ‘wpsl_store_category’
    AND term_tax.taxonomy = ‘wpsl_custom_category’
    AND term_tax.term_id = %d”;`

    I guess I’m not declaring the sql query the right way…is it so? Could you help with this or it is out of your support?

    Thread Starter rrfranco92

    (@rrfranco92)

    Hey,

    I’ve managed to get both categories working but it seems I’m facing a problem which is the plugin accepts one category but only if the other is not defined.

    Do you have any suggestion on how to get both categories to be searchable?

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

The topic ‘Adding a custom taxonomy Custom Categories’ is closed to new replies.