Wordpress 中的 get_children() 函数忽略自定义帖子类型的 orderby 和 order 参数

问题描述 投票:0回答:0

我在 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 参数(帖子仍然按创建日期排序)。根据文档,它应该可以工作。

有什么想法吗?

wordpress sql-order-by custom-post-type posts
© www.soinside.com 2019 - 2024. All rights reserved.