Sample Usage


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..)
	}
FAQ Index


  • Mika

    If i understand correctly the ‘
    force_no_custom_order’ is still usable along with Autosort is Turned ON, to overwrite a custom order for a theme query ?

    • nspcode

      Yes that is correct. This parameter will allow to control the order as default/custom independently of the Autosort status.

  • Alexandre Lino

    Very nice plugin. However, when the plugin is acftivated, i´m unable to sort my post or page list by title or date by clicking at column name in admin. Sorry if is an old question, couldn´t find any references about this issue. Thanks, nice work!

    • nspcode

      From my knowledge this has never been a problem of Advanced Post Types Order, but an issue with the free Post Types Order which was fixed months ago.
      However if you are using an older version that 2.5.3.6 you should update.

      • Alexandre Lino

        That´s correct, i´m using the free version (1.5.4) Is there a fix for the free version? I´m considering to buy ATO in few days. Thanks for de information.

        • nspcode

          Sorry but this board is only for the Advanced Post Types Order only.
          There should be a fix for that in the next release of the free plugin, unfortunate i don’t have a time-frame for that.

  • Andrew Croce

    It seems this plugin does not work on queries called by the get_posts() function. If I switch over to using a new WP_Query() to get posts, it does. Is it possible to use this plugin with get_posts() or do I need to stick to the other method?

    • nspcode

      In fact it works fine with WordPress template get_posts(), you just need to add ‘suppress_filters’ => FALSE within the arguments as this is set as TRUE by default, meaning certain query filters are not triggered.

      Here is an example:

      $args = array(
      ‘post_type’ => ‘feature’,
      ‘suppress_filters’ => TRUE
      );
      $found_posts = get_posts($args);

  • mimetic

    I am having trouble when I use tax_query. I have ordered posts, some of which are in a sub-category. While the posts in the main category are ordered as in the drag-drop interface, the posts in the sub-category are not appearing as ordered by the drag-drop interface! For example, I have
    “cat” as the main category, and “sub-cat” is a sub-category of “cat”. Posts only in “cat” are ordered, while posts in “sub-cat” are not.

    Your example, above, suggests the posts in the sub-category get their order from their inclusion in “sub-cat”, not by the drag-drop interface?!?

    Help!

  • ZaR

    Hi im Having problems with Advance Post – Re-order. im using w0o them & wooCommerce every time i do the manual sorting of a blog post & updated it & refresh the page the default order is back.

    • nspcode

      This must be caused by a JavaScript error produced by another plugin. Please check with your browser console for a message.
      If you can’t find the problem contact us and we will check into that for you.

      • ZaR

        I tried disabling all plugins except for the Adv. Post Order my Version 2.5.7.7

  • Jason Robinson

    I am trying to use manual sorting, and a 3rd party taxonomy. I stripped everything down to just a simple get_posts with the tax query and still don’t understand why the manual sorting from the admin isn’t showing up on the front end.

    $args = array(
    ‘post_type’ => ‘attachment’,
    ‘post_status’ => ‘inherit’,
    ‘posts_per_page’ => ’50′,
    ‘orderby’=>’menu_order’,
    ‘tax_query’ => array(
    array(
    ‘taxonomy’ => ‘media-tags’,
    ‘field’ => ‘slug’,
    ‘terms’ => ‘jason-test’
    )
    )
    );

    In admin, I created and saved a manual sort for this specific tax query, I even tried adding ‘sort_id’=>’2143′ to the query array, as that is the ID of the sort, and still nothing happens. Can post link to test page if needed

    • nspcode

      You should use a custom query instead please check at http://codex.wordpress.org/Class_Reference/WP_Query
      The get_posts() does not allow filters to trigger. If you keen to use that, please include the ‘suppress_filters’ => false within your $args array

      • Jason Robinson

        Thanks for getting back to me quickly! I tried ‘suppress_filters’ => false, and it doesn’t produce the desired results. I also noticed that if I suppress filters, it reverts back to the original upload order. Should I try not to use sort_id and let the tax matching do it’s thing?

        If you thing get_posts() is getting in my way, I will work on switching to wp_query (I tried this already but got stuck elsewhere).

        • Jason Robinson

          using wp_query got me what I was looking for, so no need to reply.

        • Jason Robinson

          OK so even using a base wp_query, the issue occurs when I use multiple taxonomies:

          $args = array(
          ‘post_type’ => ‘attachment’,
          ‘post_status’ => ‘inherit’,
          ‘posts_per_page’ => ’1000′,
          ‘orderby’=>’menu_order’,
          ‘tax_query’ => array(
          array(
          ‘taxonomy’ => ‘media-tags’,
          ‘field’ => ‘slug’,
          ‘terms’ => array(‘jason-test’,'portfolio’),
          ‘operator’ => ‘AND’
          )
          )
          );

          I get the right images, but they are no longer in the manual order, even though I’ve updated the manual order to include both ‘jason-test’ and ‘portfolio’. Taxonomy relationship is set to ‘AND’. Ideas?

          • Jason Robinson

            Not sure what to here, I’ve been experimenting with different ways to attack this and nothing seems to work

  • Inge van Bremen-Valstar

    Is it possible to limit posts to only direct children within a category? Now I also get all posts that live in subcategories (posts are woocommerce products)?