Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

PHP

Oredr posts by custom field

<?php query_posts($query_string. '&orderby=meta_value&meta_key=wpcf-datum-pocetka&order=ASC' ); ?>
https://snipt.net/embed/b077986fd382298797ee22885d4f2adf/
https://snipt.net/raw/b077986fd382298797ee22885d4f2adf/
b077986fd382298797ee22885d4f2adf
php
PHP
1
2016-11-21T11:36:12
True
False
False
/api/public/snipt/42829/
oredr-posts-by-custom-field
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</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 class="nx">query_posts</span><span class="p">(</span><span class="nv">$query_string</span><span class="o">.</span> <span class="s1">&#39;&amp;orderby=meta_value&amp;meta_key=wpcf-datum-pocetka&amp;order=ASC&#39;</span> <span class="p">);</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"custom fields", sort, wordpress

PHP

Display custom fields outside the loop

1
2
3
4
5
6
<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'Your-Custom-Field', true);
wp_reset_query();
?>
https://snipt.net/embed/36e90d0be3c05372538fe7262c6d251b/
https://snipt.net/raw/36e90d0be3c05372538fe7262c6d251b/
36e90d0be3c05372538fe7262c6d251b
php
PHP
6
2016-11-16T00:32:43
True
False
False
/api/public/snipt/26746/
display-custom-fields-outside-the-loop
<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></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="k">global</span> <span class="nv">$wp_query</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">$postid</span> <span class="o">=</span> <span class="nv">$wp_query</span><span class="o">-&gt;</span><span class="na">post</span><span class="o">-&gt;</span><span class="na">ID</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="k">echo</span> <span class="nx">get_post_meta</span><span class="p">(</span><span class="nv">$postid</span><span class="p">,</span> <span class="s1">&#39;Your-Custom-Field&#39;</span><span class="p">,</span> <span class="k">true</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a><span class="nx">wp_reset_query</span><span class="p">();</span> </span><span id="L-6"><a name="L-6"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"custom fields", loop, wordpress
Copyrighted, illegal, or inappropriate content? Email [email protected].