Forums Forums Search & Filter Pro Default option on load

Viewing 9 posts - 1 through 9 (of 9 total)
  • Anonymous
    #76116

    Hi Guys,

    Great plugin 🙂

    QQ – is there a way to set a taxonomy dropdown to have a default option showing those matching results on page load (i.e a preselected option)? Critical piece of this site.

    Is there a gist out there already I can use or work with before hitting the code deck (assuming someone else would have done this? Something that hooks into the $input_object I’m assuming?

    Thank you!

    Trevor
    #76149

    Yes is the answer, using our sf_edit_query_args filter.

    There are many examples of usage also post here on the forum, a key term search for that filter name should yield some.

    Anonymous
    #76187

    Hey Trevor,

    Thank you.

    After numerous other options I tried the below but not sure I’m in the right zone (the custom class is added to the field so it’s partly working).

    I just want to pull one of the options from that dropdown as the default on that page (selected option on page load).

    Any pointers?

    Thank you!

    <?php function filter_input_object($input_object, $sfid) {
    if ($input_object[‘name’] == ‘_sft_testcat’) {
    $input_object[‘defaults’] = array(“Test”);
    $input_object[‘attributes’][‘class’] = ‘mynew_class’;
    }

    return $input_object;

    }
    add_filter(‘sf_input_object_pre’, ‘filter_input_object’, 10, 2); ?>

    Trevor
    #76189

    I think you are using the wrong filter. It is the one on the docs page above this one you used?

    Anonymous
    #76257

    Can’t get it working with that either (using the taxonomy terms in the $query_args?) – do you have a specific example you can point me to that I can take a look at?

    Trevor
    #76307

    Before the user goes to the page with the pre-selected search term on, d they click a link? What is it that is pre-selected? For example, is it a taxonomy, tag or category term that can also be seen in the URL?

    Anonymous
    #76408

    No when the page loads it just needs that dropdown to be preselected. It’s a taxonomy (so term in the dropdown to be selected). Not creating bookmarkable URLs.

    Anonymous
    #76423

    I have tried numerous ways to do this without much luck including the function above, a standard jquery function and functions (init & ajax finish) on ajax finish load (as per Q1 here – https://www.designsandcode.com/wordpress-plugins/search-filter-pro/faqs/).

    Ideally I’d love to just set one of the dropdown options as the selected value (either when the page loads or when the other dropdown is clicked – this one I’m setting it on is hidden).

    More than happy to do it via $(“select option[value=’test’]”).attr(“selected”,”selected”);

    I just need to get that working in a place it executes on the page!

    The page with the form is a single-taxonomy.php and has 2 taxonomy dropdown on it (one that the user sees and one that’s hidden that I’d like to set the taxonomy term on). This all works correctly if both dropdown are visible and the user selects the term – so it’s just figuring out how to set the term on the hidden dropdown when the page loads or when the user clicks on the available taxonomy dropdown to them (i’ve tried an on change event without luck).

    Trevor
    #76499

    And you have tried a javascript that runs when the document has loaded to set the value? Why does that not work? I have done this many times before.

Viewing 9 posts - 1 through 9 (of 9 total)