2016-09-23 93 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); 
相關問題