How to loop a custom post type following the menu_order?

1

On a static page in wordpress I'm looping a custom post type from a list of services as follows:

$temp = $wp_query;  
$wp_query = null;  
$wp_query = new WP_Query();  
$wp_query->query('showposts=14&post_type=servicos'.'&paged='.$paged);  

while ($wp_query->have_posts()) : $wp_query->the_post();  

the_excerpt('');  

endwhile;  

$wp_query = null;  
$wp_query = $temp;  // Reset  

Next I load a list of specialties through the code below:

wp_list_categories('taxonomy=Servicos&title_li=');  

I both needed to sort by following the order of the menu_order column in the wp_posts table. How could he do that?

    
asked by anonymous 21.07.2014 / 07:18

1 answer

1

You need to take a look at WordPress documentation, since the reference page for WP_Query is documented the parameters of order_by where you can use menu_order , and the way you are doing this query using global $wp_query is not correct. Another thing wrong is that showposts is obsolete since the WordPress 2.1 that came out in January 2007 ...

Here is the code of how it should be following the WordPress standards:

$new_query = new WP_Query( array(
    'posts_per_page' => 14,
    'post_type'      => servicos,
    'orderby'        => 'menu_order',
    'paged'          => $paged
) );

while ( $new_query->have_posts() ) : $new_query->the_post();  

the_excerpt('');  

endwhile;  
wp_reset_postdata();

For wp_list_categories() , there is no way to sort by menu_order , see parameters accepted by function in the documentation and realize that menu_order is only for posts and not for the terms of its taxonomy, in the case for taxonomies it is possible to use term_order , however to use term_order it is necessary to work with wp_get_object_terms() that accepts it such as parameter .

    
21.07.2014 / 15:36