snipt

Ctrl+h for KB shortcuts

PHP

Query: mostrar posts de una taxonomía dinámicamente

<?php query_posts( array( 'post_type' => 'POSTTYPE', 'taxonomy'=>'TAXONOMIA', 'term'=>$term->slug )); if (have_posts()) :  while (have_posts()) : the_post(); ?>
https://snipt.net/embed/1fad744fbc3d8d99f09dae47e3a10d65/
https://snipt.net/raw/1fad744fbc3d8d99f09dae47e3a10d65/
1fad744fbc3d8d99f09dae47e3a10d65
php
PHP
1
2016-09-28T15:47:57
True
False
False
Jan 25, 2013 at 08:42 AM
/api/public/snipt/54457/
query-mostrar-posts-de-una-taxonomia-dinamicamente
<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 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="k">array</span><span class="p">(</span> <span class="s1">&#39;post_type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;POSTTYPE&#39;</span><span class="p">,</span> <span class="s1">&#39;taxonomy&#39;</span><span class="o">=&gt;</span><span class="s1">&#39;TAXONOMIA&#39;</span><span class="p">,</span> <span class="s1">&#39;term&#39;</span><span class="o">=&gt;</span><span class="nv">$term</span><span class="o">-&gt;</span><span class="na">slug</span> <span class="p">));</span> <span class="k">if</span> <span class="p">(</span><span class="nx">have_posts</span><span class="p">())</span> <span class="o">:</span> <span class="k">while</span> <span class="p">(</span><span class="nx">have_posts</span><span class="p">())</span> <span class="o">:</span> <span class="nx">the_post</span><span class="p">();</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"custom post type", loop, taxonomia, wordpress

PHP

Loop Custom Post Type

1
2
3
4
5
6
<?php query_posts( array( 'post_type' => 'slug') ); if (have_posts()) :  while (have_posts()) : the_post(); ?>
<?php // Imprimir metabox
echo get_post_meta($post->ID, 'ecpt_contact', true); ?>
// bla bla bla
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
https://snipt.net/embed/33c39954ae154c5428941dd7112627f1/
https://snipt.net/raw/33c39954ae154c5428941dd7112627f1/
33c39954ae154c5428941dd7112627f1
php
PHP
8
2016-09-28T06:33:40
True
False
False
/api/public/snipt/41354/
loop-custom-post-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></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 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;slug&#39;</span><span class="p">)</span> <span class="p">);</span> <span class="k">if</span> <span class="p">(</span><span class="nx">have_posts</span><span class="p">())</span> <span class="o">:</span> <span class="k">while</span> <span class="p">(</span><span class="nx">have_posts</span><span class="p">())</span> <span class="o">:</span> <span class="nx">the_post</span><span class="p">();</span> <span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-2"><a name="L-2"></a><span class="cp">&lt;?php</span> <span class="c1">// Imprimir metabox</span> </span><span id="L-3"><a name="L-3"></a><span class="k">echo</span> <span class="nx">get_post_meta</span><span class="p">(</span><span class="nv">$post</span><span class="o">-&gt;</span><span class="na">ID</span><span class="p">,</span> <span class="s1">&#39;ecpt_contact&#39;</span><span class="p">,</span> <span class="k">true</span><span class="p">);</span> <span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-4"><a name="L-4"></a><span class="x">// bla bla bla</span> </span><span id="L-5"><a name="L-5"></a><span class="cp">&lt;?php</span> <span class="k">endwhile</span><span class="p">;</span> <span class="k">endif</span><span class="p">;</span> <span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-6"><a name="L-6"></a><span class="cp">&lt;?php</span> <span class="nx">wp_reset_query</span><span class="p">();</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"custom post type", loop, php, wordpress
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.