2016-09-23 94 views
0

我正在为教会的一个小项目工作,我想为不同位置上发生的事件创建过滤器。是否可以自动生成带有帖子标题名称的标签?

为了方便管理,我创建了一个特定的帖子类型的事件,另一个帖子键入位置。

在位置页面中,我称之为事件,但现在所有事件都显示出来。我的想法是自动生成带有位置名称的标签,并能够从事件发布类型中选择它,以便我可以在位置页面上过滤结果。

我设法创建地点命名的自定义标签,但我还没有就如何自动生成添加到系统中每个位置的名称,这个标签的任何想法。

这是the link到我工作的页面。这是在Portugues,所以'Eventos'的意思是事件。此页面尚未翻译。

任何想法?

UPDATE:

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); 

我设法写,只要我添加后创建标签的功能,但我不能让它有职位的名称。任何想法如何实现?

回答

0

好的,我做到了!

因此,这里是我的代码:

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); 
相关问题