• Resolved byngj123

    (@byngj123)


    Hi,
    I have created a location taxonomy in my functions.php file;

    /**
     * Add custom taxonomies
     *
     * Additional custom taxonomies can be defined here
     * http://codex.ww.wp.xz.cn/Function_Reference/register_taxonomy
     */
    function add_custom_taxonomies() {
    	// Add new "Locations" taxonomy to Posts
    	register_taxonomy('location', 'post', array(
    		// Hierarchical taxonomy (like categories)
    		'hierarchical' => true,
    		// This array of options controls the labels displayed in the WordPress Admin UI
    		'labels' => array(
    			'name' => _x( 'Locations', 'taxonomy general name' ),
    			'singular_name' => _x( 'Location', 'taxonomy singular name' ),
    			'search_items' =>  __( 'Search Locations' ),
    			'all_items' => __( 'All Locations' ),
    			'parent_item' => __( 'Parent Location' ),
    			'parent_item_colon' => __( 'Parent Location:' ),
    			'edit_item' => __( 'Edit Location' ),
    			'update_item' => __( 'Update Location' ),
    			'add_new_item' => __( 'Add New Location' ),
    			'new_item_name' => __( 'New Location Name' ),
    			'menu_name' => __( 'Locations' ),
    		),
    		// Control the slugs used for this taxonomy
    		'rewrite' => array(
    			'slug' => 'locations', // This controls the base slug that will display before each term
    			'with_front' => false, // Don't display the category base before "/locations/"
    			'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
    		),
    	));
    }
    add_action( 'init', 'add_custom_taxonomies', 0 );

    and now I want to search for everything that is checked as being in a location e.g. West Midlands. I know I can do this using the drop down menus but i want to be able to do this using just the search box.
    Is there anyone out there who knows how this can be done?

    https://ww.wp.xz.cn/plugins/search-filter/

Viewing 1 replies (of 1 total)
  • Plugin Author Ross Morsali

    (@designsandcode)

    Hey byngj123

    This plugin is for allowing users to choose their search options and taxonomies, its not for defining hidden search criteria

    What it looks like you want to do is perform a search within a specific taxonomy without giving a user the option.

    This can already be achieved in vanilla WordPress.

    Goto

    www.yoursite.com/?location=westmidlandsslug&s=searchterm

    obviously replace “westmidlandsslug” with the slug of the term for westmidlands…

    so all you need is a searchbox which submits to the url

    www.yoursite.com/?location=westmidlandsslug

    If you wanted to search within multiple locations you would set the search form to:

    www.yoursite.com/?location=westmidlandsslug+location2+location3

    The rest is you’ll have to figure out as its not directly related to this plugin!

Viewing 1 replies (of 1 total)

The topic ‘Search location taxonomy using search box’ is closed to new replies.