Skip to content

Instantly share code, notes, and snippets.

@davidchc
Created August 6, 2020 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidchc/c13429881035e5fb2d85a22eee7294c3 to your computer and use it in GitHub Desktop.
Save davidchc/c13429881035e5fb2d85a22eee7294c3 to your computer and use it in GitHub Desktop.
Retorna em string os slugs
<?php
//Cria uma função pra retornar os slugs da taxonomia de um post
function getSlugsTaxonomy($post_id) {
$terms = wp_get_post_terms( $post_id, 'nome_da_sua_taxonomia', array( 'fields' => 'all' ) );
$results = array();
foreach($terms as $term) {
$results[] = $term->slug;
}
return $results ? implode(' ', $results) : '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment