我正在尝试使用显示所有子页面的列表wp_query
到目前为止,我已经创建了一个函数来检索当前页面的所有子页面,但是我需要按照自定义字段将这些页面排序为两个列表。
调用自定义字段type
它是一个具有以下值的选择字段:
product
和about
我需要根据字段值将页面列表分为两组,但我似乎无法按自定义字段对其进行分组。
我需要输出为:
Product
- Page 1
- Page 2
- Page 3
About
- Page 1
- Page 2
- Page 3
到目前为止,我有一个所有页面的列表,无法将它们分开,也无法在它们之间添加自定义字段的值。function get_child_pages($page_id, $post_type = \'page\')
{
// Set up the objects needed
$custom_wp_query = new WP_Query();
$all_wp_pages = $custom_wp_query->query(array(\'post_type\' => $post_type, \'posts_per_page\' => -1, \'order\' => \'ASC\', \'orderby\' => \'meta_value\', \'meta_key\' => \'type\', \'value\' => \'Product\',));
// Filter through all pages and find specified page\'s children
$page_children = get_page_children($page_id, $all_wp_pages);
return $page_children;
}
foreach (get_child_pages(wp_get_post_parent_id(get_the_ID())) as $s) {
echo \'<li><a href="\' . get_the_permalink($s->ID) . \'">\' . get_the_title($s->ID) . \'</a></li>\';
}