1

我正在尝试在functions.php中运行do_shortcode但没有运气

我正在使用 Types 插件http://wp-types.com/来创建自定义帖子类型和自定义字段。

我正在尝试在管理员中添加一个自定义列,以查看所有显示自定义字段缩略图的自定义帖子。

这是我到目前为止得到的,但似乎短代码在functions.php中不起作用

// add a column for custom post type (products)
add_filter('manage_product_posts_columns', 'add_thumbnail_column');
add_action('manage_product_posts_custom_column', 'add_thumbnail_content', 10, 2);

function add_thumbnail_column($defaults)
{
    $newSlice = array('thumbnail' => 'Image preview');
    $counter = 2;
    $array_head = array_slice($defaults,0,$counter);
    $array_tail = array_slice($defaults,$counter);
    $defaults = array_merge($array_head, $newSlice);
    $defaults = array_merge($defaults, $array_tail);
    return $defaults;  
}

function add_thumbnail_content($column_name, $post_ID)
{
    // this one works when putting into post content
    echo do_shortcode('[types field="square-picture" id="' . $post_ID . '" size="thumbnail"]' . '[/types]');
}

有人可以帮忙吗?

4

1 回答 1

0

在它说的功能的Wordpress注释中

“如果没有定义短代码标签,那么内容将在没有任何过滤的情况下返回。如果插件被禁用,这可能会导致问题,因为它的短代码仍会显示在帖子或内容中。”

只有当您在前端时,类型才可能有条件地声明它们的短代码。可能发生的情况是,在管理员中,未定义短代码,您只是得到了错误的返回。在前端,短代码被定义,你得到你想要的结果。

于 2013-08-14T18:45:57.513 回答