我跟踪了this tutorial 和this one 将自定义列添加到自定义帖子类型编辑屏幕,显示每篇帖子的帖子父级。我的问题是:如何使帖子父级可以像在标准管理帖子屏幕的类别列中一样单击,以便当我单击特定的帖子父级时,编辑屏幕中只显示该类别中的帖子?
根据scribu的教程,该列将填充文章父级的标题:
function manage_mytype_columns( $column, $post_id ) {
global $post;
$pp_id = get_post($post_id)->post_parent; /*The post parent id is stored also as post meta, so I could also use $pp_id = get_post_meta($post_id, \'post_parent\', true) ); */
if ( empty( $pp_id ) ) {
echo __( \'No post parent\' );}
else {
$pp_title = get_post($pp_id)->post_title;
echo $pp_title; }
}
add_action( \'manage_mytype_posts_custom_column\', \'manage_mytype_columns\', 10, 2 );
我试图实现我想要的(遵循DevPress的教程,但显然对我应该做什么没有太多了解):
function manage_mytype_columns( $column, $post_id ) {
global $post;
$pp_id = get_post($post_id)->post_parent; /*The post parent id is stored also as post meta, so I could also use $pp_id = get_post_meta($post_id, \'post_parent\', true) ); */
if ( empty( $pp_id ) ) {
echo __( \'No post parent\' );}
else {
$pp_title = get_post($pp_id)->post_title;
$pp_url = add_query_arg(array(\'post_type\' => $post->post_type, \'post_parent\' => $pp_id), \'edit.php\');
echo \'<a href="\'.$pp_url.\'">\'.$pp_title.\'</a>\'; }
}
add_action( \'manage_mytype_posts_custom_column\', \'manage_mytype_columns\', 10, 2 );
这使得帖子的父级可以点击,一旦我点击其中一个,url就像“edit.php?post\\u type=mytype&;post\\u parent=post\\u parent\\u ID”,但它仍然显示所有帖子,无论它们的父级是什么。我知道我遗漏了一些东西,可能是一些查询钩子(我也读了一些关于限制帖子钩子的内容),但我只是没有足够的知识来实现这一点。。。正确。:)请帮忙。Thx、Radu