snipt

Ctrl+h for KB shortcuts
Notice: Snipt is moving away from free accounts on May 1st, 2014. Read more about the transition here.
#57894

PHP

Wordpress modify the current query

1
2
3
4
5
<?php
query_posts(
	array_merge( $wp_query->query, array( 'posts_per_page' => 5 ) )
);
?>
https://snipt.net/embed/957578057b84cd08446a60f1cbb8253f/
https://snipt.net/raw/957578057b84cd08446a60f1cbb8253f/
957578057b84cd08446a60f1cbb8253f
php
PHP
5
2014-04-17T10:27:40
True
False
/api/public/snipt/57894/
wordpress-modify-the-current-query
<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></pre></div></td><td class="code"><div class="highlight"><pre><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="nx">query_posts</span><span class="p">(</span> </span><span id="L-3"><a name="L-3"></a> <span class="nb">array_merge</span><span class="p">(</span> <span class="nv">$wp_query</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span> <span class="s1">&#39;posts_per_page&#39;</span> <span class="o">=&gt;</span> <span class="mi">5</span> <span class="p">)</span> <span class="p">)</span> </span><span id="L-4"><a name="L-4"></a><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
query_posts, wordpress
#48289

PHP

Wordpress filter posts by comparing meta value

1
2
3
<?php
$trenutnovrijeme = strtotime('now');
query_posts( array( 'post_type' => 'javna-nadmetanja', 'orderby' => 'wpcf-datum-objave', 'meta_key' =>'wpcf-datum-zatvaranja', 'meta_compare'=>'>' ,'meta_value' => $trenutnovrijeme, 'order' => DESC, 'showposts' => 10, 'paged' => get_query_var('paged') ) ); ?>
https://snipt.net/embed/e51735c7b3e84bea17997d85b8d4a23a/
https://snipt.net/raw/e51735c7b3e84bea17997d85b8d4a23a/
e51735c7b3e84bea17997d85b8d4a23a
php
PHP
3
2014-04-23T18:15:36
True
False
Oct 09, 2012 at 04:43 AM
/api/public/snipt/48289/
wordpress-filter-posts-by-comparing-meta-value
<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></pre></div></td><td class="code"><div class="highlight"><pre><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="nv">$trenutnovrijeme</span> <span class="o">=</span> <span class="nb">strtotime</span><span class="p">(</span><span class="s1">&#39;now&#39;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="nx">query_posts</span><span class="p">(</span> <span class="k">array</span><span class="p">(</span> <span class="s1">&#39;post_type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;javna-nadmetanja&#39;</span><span class="p">,</span> <span class="s1">&#39;orderby&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;wpcf-datum-objave&#39;</span><span class="p">,</span> <span class="s1">&#39;meta_key&#39;</span> <span class="o">=&gt;</span><span class="s1">&#39;wpcf-datum-zatvaranja&#39;</span><span class="p">,</span> <span class="s1">&#39;meta_compare&#39;</span><span class="o">=&gt;</span><span class="s1">&#39;&gt;&#39;</span> <span class="p">,</span><span class="s1">&#39;meta_value&#39;</span> <span class="o">=&gt;</span> <span class="nv">$trenutnovrijeme</span><span class="p">,</span> <span class="s1">&#39;order&#39;</span> <span class="o">=&gt;</span> <span class="nx">DESC</span><span class="p">,</span> <span class="s1">&#39;showposts&#39;</span> <span class="o">=&gt;</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">&#39;paged&#39;</span> <span class="o">=&gt;</span> <span class="nx">get_query_var</span><span class="p">(</span><span class="s1">&#39;paged&#39;</span><span class="p">)</span> <span class="p">)</span> <span class="p">);</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
query_posts, wordpress