Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Give option for orderby #37

Open
nickcernis opened this issue Nov 4, 2017 · 1 comment
Open

Give option for orderby #37

nickcernis opened this issue Nov 4, 2017 · 1 comment

Comments

@nickcernis
Copy link
Contributor

nickcernis commented Nov 4, 2017

The ability to set the orderby value of the widget and shortcode would be useful, especially when applying a limit/posts_per_page.

@JiveDig
Copy link

JiveDig commented Jul 11, 2018

This would be great. Naturally need an order param too, if adding orderby.

BTW, I use Simple Page Ordering for drag and drop ordering, and have used this to default the order to menu_order. Seems like it should sort by menu order by default IMO.

// Add menu_order support to FAQ's.
add_post_type_support( 'page-attributes', 'gs_faq' );

// Set FAQ's to sort by menu_order.
add_action( 'pre_get_posts', 'prefix_faq_cpt_order' );
function prefix_faq_cpt_order( $query ) {
	// Bail if in admin.
	if ( is_admin() ) {
		return;
	}
	// Bail if not querying FAQ's.
	if ( 'gs_faq' !== $query->get( 'post_type' ) ) {
		return;
	}
	// Order by menu order.
	$query->set( 'orderby', 'menu_order' );
	$query->set( 'order','ASC' );
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants