snipt

Ctrl+h for KB shortcuts

PHP

Add query variable to WordPress

<?php
/**
 * Add 'contact' to allowed WP query variables
 */
add_action('init','add_contact_query_var');

function add_contact_query_var() {
    global $wp;
    $wp->add_query_var('contact');
}
?>
https://snipt.net/embed/adb19b5edeb96575c6f6a019165ac852/
/raw/adb19b5edeb96575c6f6a019165ac852/
adb19b5edeb96575c6f6a019165ac852
php
PHP
11
2019-06-16T00:56:47
True
False
False
Mar 12, 2013 at 11:58 AM
/api/public/snipt/57489/
add-query-variable-to-wordpress
<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> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a> <a href="#L-11">11</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="sd">/**</span> </span><span id="L-3"><a name="L-3"></a><span class="sd"> * Add &#39;contact&#39; to allowed WP query variables</span> </span><span id="L-4"><a name="L-4"></a><span class="sd"> */</span> </span><span id="L-5"><a name="L-5"></a><span class="nx">add_action</span><span class="p">(</span><span class="s1">&#39;init&#39;</span><span class="p">,</span><span class="s1">&#39;add_contact_query_var&#39;</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a><span class="k">function</span> <span class="nf">add_contact_query_var</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-8"><a name="L-8"></a> <span class="k">global</span> <span class="nv">$wp</span><span class="p">;</span> </span><span id="L-9"><a name="L-9"></a> <span class="nv">$wp</span><span class="o">-&gt;</span><span class="na">add_query_var</span><span class="p">(</span><span class="s1">&#39;contact&#39;</span><span class="p">);</span> </span><span id="L-10"><a name="L-10"></a><span class="p">}</span> </span><span id="L-11"><a name="L-11"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
query, wordpress