duanjia2415 2019-06-05 23:18
浏览 42

WP Admin(帖子列表)中的自定义列,仅显示包含的TagID数组中的标签

I ahve added a custom column to the regular Posts list in Wordpress admin.

No custom taxonomies, it should just show tags that belong to a specific array of tags.

i.e: 1 column is for Country 2 column is for Province 3 column is for News Type 4 column is for Article Type etc.

There need to be 6 columns like this.

The regular tags column will still be there, containing the same tag that this custom column has, the custom columns are needed because of the back-end logic that was requested.

so for example:

The first custom column should only show tags assigned to a post tags that have specific TagIDs (52,128,97)

The second custom column should only show tags assigned to a post tags that have specific TagIDs (875,118,27,881)

and so on.

I understand that get_the_tags() uses get_the_terms(), but get_the_terms() can only have 2 parameters, $id and $taxonomy, which is 'post_tag' in this case.

This is where I have got so far:

add_filter('manage_posts_columns', 'posts_column_custom1_country', 10);
add_action('manage_posts_custom_column', 'posts_column_custom1_country_populate', 10, 3);

function posts_column_custom1_country($defaults) {
     $defaults['customtag-country'] = __('Country');
     return $defaults;
}
function posts_column_custom1_country_populate($column_name, $id) {
     if($column_name === 'customtag-country') {
            echo get_the_terms( $id, 'post_tag');
     }
}

Notice: Array to string conversion in '...' Which is normal since what it returns is an array not a string.

How to I convert it to a string to show the actual tag names (comma separated) just like the default Tags column from Wordpress Core does?

Then how can this be set up to include an array of tagIDs so that it doesn't show all the tags assigned to the post.

There are 700+ tags used on the Wordpress site in question so excluding 780 for each of these columns only to show the 20 in the array would be a bad solution. How do I do something similar to the include parameter, which get_the_terms doesn't take unfortunately.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 回答4f系统的像差计算
    • ¥15 java如何提取出pdf里的文字?
    • ¥100 求三轴之间相互配合画圆以及直线的算法
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
    • ¥15 名为“Product”的列已属于此 DataTable
    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 自己瞎改改,结果现在又运行不了了