我在 WordPress 中使用名为“formations”的自定义帖子类型 (CPT)。在模板 single-formations.php 中有一个条件: 如果页面有children,则按照这种结构(HTML)显示children列表,如果不包含,则按照这种其他结构显示页面内容。 为此,我以这种方式使用 Wordpress 函数 get_children():
$args = array(
post_parent' => $post->ID, // Current post's ID
post_type' => 'formations',
'orderby' => 'menu_order',
'order' => 'ASC',
);
$children = get_children($args);
// Check if the post has children and if so, display the formatted list of children
if (!empty($children)) {
// Display the list of children according to the parameters orderby and order.
}
else {
// Display the page content, etc.
}
**页面参数中的order属性设置好。 ** 一切正常,除了函数似乎忽略了 order 和 orderby 参数(帖子仍然按创建日期排序)。根据文档,它应该可以工作。
有什么想法吗?