snipt

Ctrl+h for KB shortcuts

PHP

Wordpress: Search form on specific custom type

1
2
3
4
5
6
7
<form method="get" id="searchform" class="searchform" action="<?php bloginfo('home'); ?>/">
    <div class="input-append">
        <input type="hidden" name="post_type" value="event" /> <?php // This does the trick, search only on post type named "event" ?>
        <input type="text" class="span2 field" name="s" id="s" placeholder="Search" value="<?php echo wp_specialchars($s, 1); ?>" >
        <input type="submit" class="btn" name="submit" id="searchsubmit" value="OK">
    </div>
</form>
https://snipt.net/embed/125651205cb8326e51e03fe6ad9bbafb/
https://snipt.net/raw/125651205cb8326e51e03fe6ad9bbafb/
125651205cb8326e51e03fe6ad9bbafb
php
PHP
7
2016-09-30T03:51:51
True
False
True
Jan 14, 2013 at 06:24 AM
/api/public/snipt/53682/
wordpress-search-form-on-specific-custom-type
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="x">&lt;form method=&quot;get&quot; id=&quot;searchform&quot; class=&quot;searchform&quot; action=&quot;</span><span class="cp">&lt;?php</span> <span class="nx">bloginfo</span><span class="p">(</span><span class="s1">&#39;home&#39;</span><span class="p">);</span> <span class="cp">?&gt;</span><span class="x">/&quot;&gt;</span> </span><span id="L-2"><a name="L-2"></a><span class="x"> &lt;div class=&quot;input-append&quot;&gt;</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> &lt;input type=&quot;hidden&quot; name=&quot;post_type&quot; value=&quot;event&quot; /&gt; </span><span class="cp">&lt;?php</span> <span class="c1">// This does the trick, search only on post type named &quot;event&quot; ?&gt;</span> </span><span id="L-4"><a name="L-4"></a> <span class="o">&lt;</span><span class="nx">input</span> <span class="nx">type</span><span class="o">=</span><span class="s2">&quot;text&quot;</span> <span class="nx">class</span><span class="o">=</span><span class="s2">&quot;span2 field&quot;</span> <span class="nx">name</span><span class="o">=</span><span class="s2">&quot;s&quot;</span> <span class="nx">id</span><span class="o">=</span><span class="s2">&quot;s&quot;</span> <span class="nx">placeholder</span><span class="o">=</span><span class="s2">&quot;Search&quot;</span> <span class="nx">value</span><span class="o">=</span><span class="s2">&quot;&lt;?php echo wp_specialchars(</span><span class="si">$s</span><span class="s2">, 1); ?&gt;&quot;</span> <span class="o">&gt;</span> </span><span id="L-5"><a name="L-5"></a> <span class="o">&lt;</span><span class="nx">input</span> <span class="nx">type</span><span class="o">=</span><span class="s2">&quot;submit&quot;</span> <span class="nx">class</span><span class="o">=</span><span class="s2">&quot;btn&quot;</span> <span class="nx">name</span><span class="o">=</span><span class="s2">&quot;submit&quot;</span> <span class="nx">id</span><span class="o">=</span><span class="s2">&quot;searchsubmit&quot;</span> <span class="nx">value</span><span class="o">=</span><span class="s2">&quot;OK&quot;</span><span class="o">&gt;</span> </span><span id="L-6"><a name="L-6"></a> <span class="o">&lt;/</span><span class="nx">div</span><span class="o">&gt;</span> </span><span id="L-7"><a name="L-7"></a><span class="o">&lt;/</span><span class="nx">form</span><span class="o">&gt;</span> </span></pre></div> </td></tr></table>
custom, search, type, wordpress
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.