Sample Usage

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInPrint this page


The Advanced Post Types Order plugin does all work for you when Autosort setting is turned ON, however in certain situations custom queries are required to be run along with Autosort turned OFF.

Return feature post types objects, using the order set for the archive (all feature post type items):

$args = array(
			'post_type' 	=> 'feature',
			'orderby'   	=> 'menu_order',
			'order'     	=> 'ASC'
			);

$my_query = new WP_Query($args);
while ($my_query->have_posts())
	{
		$my_query->the_post();
		//(..your code..)
	}

Return feature post types objects, using the order set for the ‘movies’ taxonomy within the term called ‘Titanic’ (id 10):

$args = array(
			'post_type' => 'feature',
			'orderby'   	=> 'menu_order',
			'order'     	=> 'ASC',
			'tax_query' 	=> array(
							array(
								'taxonomy' 	=> 'movies',
								'field' 		=> 'id',
								'terms' 	=> 10
								)
							)
			);

$my_query = new WP_Query($args);
while ($my_query->have_posts())
	{
		$my_query->the_post();
		//(..your code..)
	}

There are situations when Autosort is ON and you need to exclude the order from a query to return in random order, in such situations the ignore_custom_sort parameter will help

*Since version 3.5.2 ignore_custom_sort replaced the force_no_custom_order

$args = array(
			'post_type' 				=> 'feature',
			'orderby'   				=> 'rand',
			'ignore_custom_sort' 			=> TRUE
			);

$my_query = new WP_Query($args);
while ($my_query->have_posts())
	{
		$my_query->the_post();
		//(..your code..)
	}

In case of using get posts the ‘suppress_filters’ => false need to be included as by default ‘suppress_filters’ is set as true:

$args = array(
			'post_type' 	=> 'feature',
			'orderby'   	=> 'menu_order',
			'order'     	=> 'ASC',
			'suppress_filters' => false
			);

$my_posts = get_posts($args);
foreach($my_posts as $post)
	{
		setup_postdata($post);
		//(..your code..)
	}

In case of multiple sorts which contain the same query settings, the first will apply. However this can be modified by including the ‘sort_id’ parameter, where the value is the Sort post Id.

$args = array(
			'post_type' 				=> 'feature',
			'orderby'   				=> 'menu_order',
			'sort_id'    				=>  '4211',
			);

$my_query = new WP_Query($args);
while ($my_query->have_posts())
	{
		$my_query->the_post();
		//(..your code..)
	}
API Index