查询菜单_订购自定义发布类型

时间:2011-06-22 作者:cnotethegr8

我补充道\'supports\' => \'page-attributes\' 到我的自定义帖子类型,现在我有了页面排序的元框。

当我使用参数时\'sort_column\' => \'menu_order\' 具有get_pages() 在我的自定义帖子类型上,一切都正常。

那么,当我使用query_posts(array(\'orderby\' => \'menu_order\'))

我该怎么做才能让他们按菜单顺序点菜呢?

这是我使用的查询,以防任何人想看到它。

<?php 
    $current_term = ($wp_query->query_vars[\'section\'] <> \'\') ? $wp_query->query_vars[\'section\'] : $menu_arr[0]; 
    query_posts(array(  \'post_type\' => \'module\', 
        \'orderby\' => \'menu_order\',
        \'tax_query\' => array(array( \'taxonomy\' => \'section\', 
                                    \'field\' => \'slug\', 
                                    \'terms\' => $current_term )),
        \'post_parent\' => 0 ));
?>

3 个回复
最合适的回答,由SO网友:Scott 整理而成

我必须和你做同样的事情,以下是我所做的工作:

\'supports\' => array(\'title\', \'editor\', \'thumbnail\', \'page-attributes\')

注册支持页面属性的帖子类型。这会将菜单顺序元框添加到编辑屏幕。从那里你可以下订单。

然后运行我的自定义查询:

$args = array(
    \'numberposts\' => -1,
    \'orderby\' => \'menu_order\',
    \'order\' => \'ASC\',
    \'post_type\' => \'staff\'
);
$staff = get_posts($args);
设置orderby 到menu\\u order和order 至ASC。请记住,如果不按菜单顺序设置值,则会将其设置为0。因此,任何没有订单集的帖子都会首先出现。

SO网友:Jan

在我的功能中。php我使用的是:

add_action( \'init\', \'create_Videos\' );
function create_Videos() {
    register_post_type(\'videos\', array(
        \'label\' => __(\'Videos\'),
        \'singular_label\' => __(\'Video\'),
        \'public\' => true,
        \'show_ui\' => true,
        \'capability_type\' => \'article\',
        \'hierarchical\' => true,
        \'rewrite\' => false,
        \'query_var\' => true,
        \'supports\' => array(\'title\', \'editor\', \'page-attributes\')
    ));
}
在我的主题中:

    $args = array(
        \'numberposts\' => -1,
        \'orderby\' => \'menu_order\',
        \'order\' => \'ASC\',
        \'post_type\' => \'videos\'
    );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
这对meBye有用

SO网友:OZZIE

sort_column=menu_order 仅根据页面的书写顺序而不是您在中设置的顺序对页面进行排序view > menus (已翻译),如果需要,可以这样做:

$children = get_pages(\'child_of=\'. $topID); 

// \'sort_column=menu_order\' <-- only sorts by post order in writing mode (page > edit) not the menu order set in view > menus
// wp_nav_menu has what we need, let\'s sort it the same way.
$options = array(
    \'container\' =>  \'\',
    \'echo\'      =>  false,
);                      
$nav = wp_nav_menu($options);       
$nav = strip_tags($nav);        
$nav = str_replace("\\r", \'\', $nav);
$nav = explode("\\n", $nav);
//print_r($nav);
$newChildren = array();
foreach ($nav as $item) {
    $item = trim($item);
    $run = true;
    for ($c = 0; $c < count($children) && run; $c++) {              
        $child = $children[$c];
        if (strcmp($child->post_title, $item) == 0 && !in_array($child, $newChildren)) {
            $newChildren[] = $child;                    
            $run = false;
        }
    }

    // Adding the children the nav_menu is lacking, not sure why not all sub-children 
    //  are added to the first child here..(works but don\'t know why :/)
    if ($run == true) {
        for ($c = 0; $c < count($children) && run; $c++) {              
            $child = $children[$c];     
            if (!in_array($child, $newChildren)) {
                $newChildren[] = $child;
            }
        }           
    }
}
$children = $newChildren;

结束