snipt

Ctrl+h for KB shortcuts

PHP

Get terms on a archive page

1
2
3
4
5
6
7
<?php
    $queried_object = get_queried_object();
    $term_slug = $queried_object->slug;
    
    echo $term_slug;
    
?>
https://snipt.net/embed/ad8e4eb6eb6f5cd505ca91754ba95051/
/raw/ad8e4eb6eb6f5cd505ca91754ba95051/
ad8e4eb6eb6f5cd505ca91754ba95051
php
PHP
7
2019-07-15T13:44:11
True
False
False
Nov 22, 2013 at 07:31 AM
/api/public/snipt/95975/
get-terms-on-a-archive-page
<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></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="nv">$queried_object</span> <span class="o">=</span> <span class="nx">get_queried_object</span><span class="p">();</span> </span><span id="L-3"><a name="L-3"></a> <span class="nv">$term_slug</span> <span class="o">=</span> <span class="nv">$queried_object</span><span class="o">-&gt;</span><span class="na">slug</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a> <span class="k">echo</span> <span class="nv">$term_slug</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="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
archive, query, taxonomy, terms, wordpress

Text only

Drupal 7 : List (View) of content types group by Taxonomy

1
2
3
4
5
6
7
In your view, click add in the "FIELDS" section. 
There, you can search for "Taxonomy terms" and "title" and add them both.
Uncheck "Create a label"
Check "Exclude from display" if you don't want to see on those fields (taxonomy terms for example)
Also, you can "Limit terms by vocabulary" and choose a specific taxonomy

You can now click on FORMAT / Format / Settings and set "Grouping field Nr.1" to "Taxonomy terms"
https://snipt.net/embed/82582202880575d55711a02aa9912789/
/raw/82582202880575d55711a02aa9912789/
82582202880575d55711a02aa9912789
text
Text only
7
2016-12-29T02:11:11
True
False
True
Jan 28, 2013 at 12:56 PM
/api/public/snipt/54653/
drupal-7-list-view-of-content-types-group-by-taxonomy
<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></span><span id="L-1"><a name="L-1"></a>In your view, click add in the &quot;FIELDS&quot; section. </span><span id="L-2"><a name="L-2"></a>There, you can search for &quot;Taxonomy terms&quot; and &quot;title&quot; and add them both. </span><span id="L-3"><a name="L-3"></a>Uncheck &quot;Create a label&quot; </span><span id="L-4"><a name="L-4"></a>Check &quot;Exclude from display&quot; if you don&#39;t want to see on those fields (taxonomy terms for example) </span><span id="L-5"><a name="L-5"></a>Also, you can &quot;Limit terms by vocabulary&quot; and choose a specific taxonomy </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a>You can now click on FORMAT / Format / Settings and set &quot;Grouping field Nr.1&quot; to &quot;Taxonomy terms&quot; </span></pre></div> </td></tr></table>
"drupal 7", "group by", taxonomy, view

PHP

Wordpress query Join for post - taxonomy - term

$sql="SELECT DISTINCT * FROM wp_posts INNER JOIN wp_term_relationships ON(wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON(wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) INNER JOIN wp_terms ON(wp_term_taxonomy.term_id = wp_terms.term_id) WHERE (wp_terms.name LIKE '% {$search_keyword}%' OR wp_terms.name LIKE '{$search_keyword}%' OR wp_posts.post_title LIKE '% {$search_keyword}%' OR wp_posts.post_title LIKE '{$search_keyword}%') AND wp_posts.post_status='publish'";
$search_products = $wpdb->get_results($sql, OBJECT);
https://snipt.net/embed/424bc93629689d496b8b27c8c5748a06/
/raw/424bc93629689d496b8b27c8c5748a06/
424bc93629689d496b8b27c8c5748a06
php
PHP
2
2019-07-06T01:35:52
True
False
False
Jan 27, 2013 at 08:04 AM
/api/public/snipt/54584/
wordpress-query-join-for-post-taxonomy-term
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x">$sql=&quot;SELECT DISTINCT * FROM wp_posts INNER JOIN wp_term_relationships ON(wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON(wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) INNER JOIN wp_terms ON(wp_term_taxonomy.term_id = wp_terms.term_id) WHERE (wp_terms.name LIKE &#39;% {$search_keyword}%&#39; OR wp_terms.name LIKE &#39;{$search_keyword}%&#39; OR wp_posts.post_title LIKE &#39;% {$search_keyword}%&#39; OR wp_posts.post_title LIKE &#39;{$search_keyword}%&#39;) AND wp_posts.post_status=&#39;publish&#39;&quot;;</span> </span><span id="L-2"><a name="L-2"></a><span class="x">$search_products = $wpdb-&gt;get_results($sql, OBJECT);</span> </span></pre></div> </td></tr></table>
join, mysql, posts, query, taxonomy, wordpress

PHP

Imprimir Current Taxonomy sin links

1
2
3
4
<?php
$terms_as_text = get_the_term_list( $post->ID, 'your-custom-taxonomy-name', '', ', ', '' ) ;
echo strip_tags($terms_as_text);
?>
https://snipt.net/embed/13f2c139728a21f8d16018c02f4b6f85/
/raw/13f2c139728a21f8d16018c02f4b6f85/
13f2c139728a21f8d16018c02f4b6f85
php
PHP
4
2019-07-08T23:15:02
True
False
False
Dec 07, 2012 at 04:00 PM
/api/public/snipt/51428/
imprimir-current-taxonomy-sin-links
<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></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="nv">$terms_as_text</span> <span class="o">=</span> <span class="nx">get_the_term_list</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;your-custom-taxonomy-name&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;, &#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span> <span class="p">)</span> <span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="k">echo</span> <span class="nb">strip_tags</span><span class="p">(</span><span class="nv">$terms_as_text</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
links, taxonomy, terms, wordpress