![](/img/trans.png)
[英]Wordpress. How to get the custom post_type count in taxonomy.php page
[英]Wordpress. How to give parent page to a page create dinamiccaly in PHP
我正在創建一個小腳本以動態創建頁面(如果該頁面不存在),但是我遇到了問題。 我要為要創建的頁面提供父頁面。
用幾句話說:
如果頁面已創建,則為其提供父頁面。
我想要的輸出是:
http://exemple.com/ParentPage/ChildPage
並在后端自動在“頁面”屬性中顯示“父頁面”,而不是“(無父)”
function check_pages_live(){
if(get_page_by_title('Page Title') == NULL ) {
create_pages_fly('Page Title');
}
}
add_action('init','check_pages_live');
function create_pages_fly($pageName) {
$parentPost = get_post( 2167 );
$createPage = array(
'post_title' => $pageName,
'post_content' => 'Some Content',
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'page',
'post_parent' => $parentPost,
'post_name' => $pageName
);
// Insert the post into the database
wp_insert_post( $createPage );
}
我試圖用get_post和父頁面的ID創建一個類。 我已經將其添加到函數中,但是沒有任何效果。
有人可以幫我嗎?
非常感謝
查看文檔 ,“ post_parent”應為整數。 將其設置為“ post_parent” => 2167應該可以解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.