I am working in a shortcode for visual composer grid. I want to show the list of terms of a taxonomy (portfolio_tag) associated to a custom post type (portfolio). The shortcode gets the ID from the post correctly, but it is a string, not a number. When I try to use (int) or (intval) to change it to an integer it returns 0. So wp_get_post_terms is not working.
add_shortcode( 'proyectotag', 'ona_proyectotag' );
function ona_proyectotag($atts) {
// Attributes
extract( shortcode_atts(
array(
'id' => '{{ post_data:ID }}',
), $atts )
);
$tags="";
$term_list = wp_get_post_terms($id, 'portfolio_tag');
foreach($term_list as $term_single) {
$tags.= $term_single->slug;
}
return $tags;
}
What can I do? I don't understand what is happening! Could anybody help me? I feel like I have tried almost everything
I am working in a shortcode for visual composer grid. I want to show the list of terms of a taxonomy (portfolio_tag) associated to a custom post type (portfolio). The shortcode gets the ID from the post correctly, but it is a string, not a number. When I try to use (int) or (intval) to change it to an integer it returns 0. So wp_get_post_terms is not working.
add_shortcode( 'proyectotag', 'ona_proyectotag' );
function ona_proyectotag($atts) {
// Attributes
extract( shortcode_atts(
array(
'id' => '{{ post_data:ID }}',
), $atts )
);
$tags="";
$term_list = wp_get_post_terms($id, 'portfolio_tag');
foreach($term_list as $term_single) {
$tags.= $term_single->slug;
}
return $tags;
}
What can I do? I don't understand what is happening! Could anybody help me? I feel like I have tried almost everything
Share Improve this question asked Feb 19, 2016 at 10:16 Laia misEfectosLaia misEfectos 11 bronze badge 4 |1 Answer
Reset to default -1$term_list = wp_get_post_terms($post->ID, 'product_features', array("fields" => "all"));
foreach($term_list as $term_single) {
echo $term_single->slug;
//do something here
}
string(18) "94"
If I do$id=(int)$id
it returns `int(0) – Laia misEfectos Commented Feb 19, 2016 at 12:03