[英]Is it possible to automatically generate a tag for with a post title name?
我正在为教堂做一个小项目,在这里我想为发生在不同位置的事件创建过滤器。
为了便于管理,我为事件创建了一个特定的帖子类型,并为该位置创建了另一个帖子类型。
在位置页面中,我调用了事件,但是现在所有事件都在显示。 我的想法是使用位置名称自动生成标签,并能够从事件发布类型中选择它,因此我可以在位置页面上过滤结果。
我设法创建了一个以位置命名的自定义标签,但是我对如何从添加到系统的每个位置的名称中自动生成此标签一无所知。
这是我正在工作的页面的链接 。 它在葡萄牙语中,因此“ Eventos”表示事件。 此页面尚未翻译。
有任何想法吗?
更新:
function on_post_publish( $ID, $post ) {
//Define the category
$my_cat = array('cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => '', 'taxonomy' => 'unidadeseventos');
// Create the category
$my_cat_id = wp_insert_category($my_cat);
}
add_action( 'publish_unidades', 'on_post_publish', 10, 2 );
我设法编写了一个函数,可以在添加帖子后立即创建标签,但无法获得带有该帖子名称的标签。 关于如何实现这一目标的任何想法?
好吧,我做到了!
所以这是我的代码:
function on_post_publish( $ID, $post ) {
// Get post title
$parent_title = get_the_title( $post->post_parent );
//Define the category
$my_cat = array('cat_name' => $parent_title, 'category_description' => '', 'category_nicename' => '', 'category_parent' => '', 'taxonomy' => 'unidadeseventos');
// Create the category
$my_cat_id = wp_insert_category($my_cat);
}
add_action( 'publish_unidades', 'on_post_publish', 10, 2 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.