最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Shortcode for Visual Composer Grid fails turning string to integer

programmeradmin1浏览0评论

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
  • Which value do you see in the post ID string? – cybmeta Commented Feb 19, 2016 at 10:43
  • If I do var_dump it returns: string(18) "94" If I do $id=(int)$idit returns `int(0) – Laia misEfectos Commented Feb 19, 2016 at 12:03
  • That is, well, impossible? Let me check it. – cybmeta Commented Feb 19, 2016 at 12:33
  • I wish it was impossible! Have you checked it? Do you need more information? – Laia misEfectos Commented Feb 19, 2016 at 13:54
Add a comment  | 

1 Answer 1

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
}
发布评论

评论列表(0)

  1. 暂无评论