2014-05-23 33 views
0

後重定向到edit.php我已經創建了新的自定義文章類型 - wordpress中的交易,它重新定向到edit.php(職位列表)發佈新交易後。所以我想重定向到交易列表頁面(http://mydemo.com/demo/edit.php?post_type=deals),所以請幫助我。我的自定義文章類型重定向到wordpress後發佈和更新發布

我試過這個代碼,但它將所有的帖子類型重定向到指定的頁面。

add_filter('redirect_post_location', 'wpse_124132_redirect_post_location'); 
/** 
* Redirect to the edit.php on post save or publish. 
*/ 


function wpse_124132_redirect_post_location($location) { 

    if (isset($_POST['save']) || isset($_POST['publish'])) 
     return admin_url("edit.php?post_type=deals"); 

    return $location; 
} 

回答

2

您需要使用get_post_type()函數。

更改您的代碼

function wpse_124132_redirect_post_location($location) { 

    if ('deals' == get_post_type()) { 

    /* Custom code for 'deals' post type. */ 

     if (isset($_POST['save']) || isset($_POST['publish'])) 
      return admin_url("edit.php?post_type=deals"); 

    } 
    return $location; 
} 

編輯:由於您使用的get_post_type()之外的的循環你需要通過帖子的ID,

get_post_type($_POST['id'])

相關問題