0

I need to add the following string :

=&a=true

To the end of all search URLs, but only those generated by the form below. So instead of this URL :

https://website.com/?s=tool&post_type=ait-item

It would display this URL :

https://website.com/?s=tool&post_type=ait-item=&a=true

I suspect I could do it by editing the custom search form, but am unsure how to accomplish this. This is the search form :

<div class="search-box">
    <div class="container">
        <div class="columns">
            <form method="get" class="nt-search-form" action="<?php echo home_url(); ?>">
                <input type="text" id="search-text" class="input-text" name="s" placeholder="<?php _e('Search &#8230;', 'customsearch');?>" autocomplete="off" />
                <input type="hidden" name="post_type" value="ait-item" />
                <i class="fa fa-times close-button" aria-hidden="true"></i>
            </form>
        </div>
    </div>
</div>

Any insight would be much appreciated.

1

This can be done in multiple ways But the easiest will be the following code.

The key is the GET method that will allow us to inject what you want.

You can try:

<div class="search-box">
    <div class="container">
        <div class="columns">
            <form method="get" class="nt-search-form" action="<?php echo home_url(); ?>">
                <input type="text" id="search-text" class="input-text" name="s" placeholder="<?php _e('Search &#8230;', 'customsearch');?>" autocomplete="off" />
                <input type="hidden" name="post_type" value="ait-item" />
                <input type="hidden" name="a" value="true" />
                <i class="fa fa-times close-button" aria-hidden="true"></i>
            </form>
        </div>
    </div>
</div>

Update

I marked out the =&a=true the first equal as this will be set the GET variable post_type to include the equal symbol.

If this actually what you want you to have to replace with this line <input type="hidden" name="post_type" value="ait-item=" />

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.