首页 > 解决方案 > 如何正确匹配标签名称?

问题描述

此代码应将标签名称与表单标题匹配,以输出正确的表单,以允许用户订阅具有当前帖子标签的新帖子。

add_shortcode( 'subscribe-to-the-tag', function() {
   global $wpdb, $post;
 
$the_tag = get_the_tags( $post->ID );
$tag_name = $the_tag[0]->tag_name;
   $id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM wptq_forms WHERE name = '{$tag_name}';"));
   if (is_null($id)) { return ''; }
   return do_shortcode( '[newsletter_form id="' . intval( $id ) . '"]' );
} );    

标签: mysqlwordpressformstags

解决方案


推荐阅读