You probably also need:
$query->set( 'ignore_sticky_posts', true );
That will prevent sticky posts from shuffling to the top.
Maybe:
$query->set( 'posts_per_page', -1 );
If you are getting too few posts. -1
means “all”. You can use that to change to a number other than what is set in the backend.
A couple of notes:
$query->set( 'meta_key', 'key name' );
will limit the results to
posts with thatmeta_key
- If your
meta_value
for thekey name
isn’t really a number the
order isn’t going to work correctly. Punctuation and letters will mess this up. is_home
can be peculiar. Make sure it does what you need it
to do.
Beyond that, you will need to explain “not returning all the posts and not ordering them properly” in better detail.