用于在 pods 插件中显示自定义分类法的简码 - wordpress

shortcode for displaying custom taxonomy with description in pods plugin - wordpress

我使用 pods plugin and inside that plugin i have defined a label named 'details'. what i want to do is to generate a short code in which returns that details. i have searched my way through lots of documentation, but could not find one.image showing the custom field i have added inside the taxonomy

创建了一个名为 'singer' 的自定义分类法

感谢您的帮助!

需要这么复杂吗? (意思是,你需要插件吗?)

在你的函数中注册一个新的分类"singer":

            function taxonomies_init() {
                // create a new taxonomy
                register_taxonomy(
                    'singer',
                    'post',
                    array(
                        'label' => __( 'Singer' ),
                        'rewrite' => array( 'slug' => 'singer' ),
                    )
                );
            }
            add_action( 'init', 'taxonomies_init' );

注册简码:

            function showtax_func( $atts ) {

            if (is_single()) {
                $a = shortcode_atts( array(
                    'tax' => '',
                ), $atts );

                $termname = get_the_terms(get_the_ID(),$a['tax'])[0]->name;
                return $termname;
                }

            }
            add_shortcode( 'show_tax', 'showtax_func' );

像这样使用简码:[show_tax tax="singer"]

您可以通过复制 register_taxonomy() 函数扩展第一个函数来添加更多分类法。只需更改分类法名称的值即可使用简码获取任何分类法。