Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Eyal Fitoussi

    (@ninjew)

    Hi Chris,
    Take a look at this post. This might be the solution to what you are looking for.

    Thread Starter chrisdavisberry

    (@chrisdavisberry)

    That looks like it will do it.

    I will plan out what defaults i need then once added i will let you know how it worked.

    Many thanks
    Chris

    Plugin Author Eyal Fitoussi

    (@ninjew)

    Great!

    Thread Starter chrisdavisberry

    (@chrisdavisberry)

    Hi Eyal,

    I got this solution working really nicely to generate a list of results on initial page view using a version of the code you supplied.

    The issue I still have is once the page has loaded I was trying to allow the user to search posts but only searching terms that match the initial query.

    For example: when a user visits http://handheld.simplecsr.com/test-historic/ they only see results matching the Route Type > Historic Walks

    But when they search using the on page form can these results be limited to only include results matching Historic Walks (without the user having to manually set the filter.)

    Many thanks
    Chris

    Thread Starter chrisdavisberry

    (@chrisdavisberry)

    Hi Eyal,

    Sorry i forgot to add… If necessary it would be sufficient to make the drop down Route Type default to a specific term (in this example Historic Home Walks.

    I have been looking at adapting one of the scripts you provided to do this:

    function gmw_modify_taxonomy( $args, $gmw, $taxonomy ) {
    
    	//check that we are within form ID 1, otherwise do nothing
    	if ( $gmw['ID'] != 1 )
    		return $args;
    
    	//check that this is 'category' taxonomy, otherwise do nothing
    	if ( $taxonomy->name != 'category' )
    		return $args;
    
    	//modify the show_option_all of the taxonomy which is responsible
    	//of the default value of the drop-down select box
    	$args['show_option_all'] = ' All Categories';
    
    	//return the modifyed args
    	return $args;
    
    }
    add_filter( 'gmw_pt_dropdown_taxonomy_args', 'gmw_modify_taxonomy', 10, 3 );

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Thanks
    Chris

    Thread Starter chrisdavisberry

    (@chrisdavisberry)

    hi,

    A method may be to edit the custom results template for that form and edit the custom loop to exclude results not using the matching taxonomy term.

    <?php while ( $gmw_query->have_posts() ) : $gmw_query->the_post(); ?>

    I could then hide the route type filter from that form.

    Can this be done in the custom results.php template that I am using.

    Thanks
    Chris

    Plugin Author Eyal Fitoussi

    (@ninjew)

    The declaration of the WP_query is happening before the results.php file. However, there is a filter that you could use in order to modify the wp_query.

    open the file geo-my-wp/plugins/posts/includes/gmw-pt-search-functions.php and around line 705 you will see the filter

    apply_filters( 'gmw_pt_form_before_posts_query', $this->form, $this->settings );

    try using this filter.

    Thread Starter chrisdavisberry

    (@chrisdavisberry)

    Hi Eyal,

    But any changes here would not survive an update and I need to do this for at least 4 different forms on the site.

    Is there a premium extension which will restict search results (or the posts that are searched by a form) to only those in a given taxonomy term?

    If their isn’t then going back to my original example -http://handheld.simplecsr.com/countryside-walks/ is there a method to set the default of the form “Route type” dropdown to a specific term “Countryside Walks” in this example.

    Thanks
    Chris

    Plugin Author Eyal Fitoussi

    (@ninjew)

    Hi Chris,
    You do not need to edit the original file of the plugin. Filters are provided to you so you could modify code and variable by placing a function in the function.php file of your theme instead of modifying the core files.

    It shouldn’t be difficult. Here you can read a bit about filters.

    This post is about wp_query. You can look for how to include only a certain taxonomy. and using the filter above you can modify the query of GEO my WP.

    Otherwise you can take a look at the Premium Settings add-on. Using the add-on you can include/exclude different taxonomies of a post type ( along with many other premium features ).

    Plugin Author Eyal Fitoussi

    (@ninjew)

    I just realized that I haven’t updated the add-on description after the last update so the information about the taxonomies is not there.
    But basically you can choose to include or exclude certain taxonomies of a post type, you can exclude certain terms from a taxonomy ( by term ID ), you can order taxonomies and terms and you can display taxonomies using drop down select-box or checkboxes.

    Thread Starter chrisdavisberry

    (@chrisdavisberry)

    Hi Eyal,

    I am going back to my very first query and I wonder if you can recommend something.

    I am wondering if there is a method to set a default value on a Search Form dropdown.

    For example:

    On http://handheld.simplecsr.com/countryside-walks/ I have a dropdown Category for “Route Type”.

    I would like this to default to “Countryside Walks” (one of the terms) instead of “All Route Types” if possible.

    Thanks
    Chris

    Plugin Author Eyal Fitoussi

    (@ninjew)

    Open the file:
    geo-my-wp/plugins/posts/search-forms/horizontal-gray/search-form.php
    and around line 34 which is:

    $args['show_option_all'] = ' All '.$get_tax->labels->name;

    change it to :

    $args['show_option_all'] = false;

    this should remove the “All” option of the drop down and will make Countryside Walk default.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Method to set a default option on a Search Form Dropdown’ is closed to new replies.