+88 01797-506292

Post Date: October 25, 2017
Posted By: admin

Add order by in post query, have_post using pre_get_posts hook

Add this hook in functions.php file

add_action('pre_get_posts','set_posts_argument');

function set_posts_argument( $query )
{
	if (!is_admin() && (is_post_type_archive('resources') || is_post_type_archive('projects') || is_post_type_archive('services') ) ) {
		$query->set('orderby', 'menu_order');
		$query->set('order', 'ASC');
	}
}

2 responses to “Add order by in post query, have_post using pre_get_posts hook”

  1. LuciaArild says:

    Eat at Burger King For a Year!
    Go to the site.
    Enter your email now for a chance to win Burger King lunch for a year.

  2. KrisArild says:

    Eat at Burger King For a Year!
    Go to the http://burger.socaf.info – site.
    Enter your email now for a chance to win Burger King lunch for a year.

Leave a Reply

Your email address will not be published. Required fields are marked *