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.
Related Posts:
- Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
- How do I query for a post by custom field?
- using multiple meta_key and meta_value in query_posts
- meta_compare seems to be treating values as strings instead of integers as expected
- Limits, not all post are showen when querying for posts by view count
- Unable to get specific value from post meta
- Custom search SQL Query to add custom field in result
- Custom Query: query by post custom meta data
- Get author total post votes from post meta
- searching by keywords in post’s metas or pagination links problem
- what is the correct way to compare dates in a WP query_posts meta_query
- How to get custom post meta using REST API
- The “_encloseme” Meta-Key Conundrum
- Using get_post_meta with new_to_publish
- Meta Query with AND & OR?
- Can I count the number of users matching a value in a multiple value key?
- Auto sort the wp-admin post list by a meta key
- Filter archive.php by custom meta
- Get updated meta data after save_post hook
- Save HTML formatted data to post meta using add_post_meta()
- Query on custom field count?
- How to break meta values into different items and avoid duplicates?
- ajax delete value from custom field array
- Save attachment custom fields on front end
- Transition from (classical) serialized custom meta field to (gutenberg) rest enabled meta
- Unable to show ACF’s Image Custom Field properly in Genesis Framework [closed]
- Custom field value based on other custom field values
- meta_value_num sort glitch
- Order by value in serialized custom field
- meta query not showing any results?
- How to display Meta Field Value?
- Upcoming Event: How do I sort database by custom date field, but ignore past dates?
- Combine multiple custom field values into single value
- How to query posts with certain custom meta data, and output Post data
- Can’t get post ID using wp_insert_post_data
- Unique Post Meta Values
- Show 1 post and after a specific date show the next one
- query usermeta from custom field
- Fetch Record based on meta key dates
- Add post meta fields, when creating a post using WordPress’ REST API
- Store array as single, serialized post meta field or many post meta fields?
- Custom Field Values not updating unless I click “Update” twice
- update_post_meta for repeated custom field [closed]
- Trying to update_post_meta function
- Custom fields (wp_post_meta) vs Custom Table for large amount of data
- get_posts in meta box dropdown not showing latest posts
- Trying to reorder posts by custom field
- filter custom field values $min $max
- Ordering posts by custom field named “date” in backend
- Unique meta_key with array value vs repeated meta_key with single values
- Allow only one post with specific meta value
- How to validate select field in post meta?
- How to display childrens custom fields?
- how to display custom fields of post on a web page
- Exclude posts by post meta value
- How do I query the title (or handle?) of post meta fieldset (created with Simple Fields Plugin)
- List custom queried terms in the edit-tags.php?taxonomy page
- How to fill custom fields with brackets in their key with add_post_meta()?
- change order of images attached to post
- how can I show name and value of Custom Fields together?
- Loop through incrementing custom fields
- Gravity Forms Update post meta from template [closed]
- put saved metabox values back into fields and then display on the front end
- How to get custom image field of specific post id
- How to query for posts with either one or another custom field
- How to query posts by month based on date custom field?
- How can I change author of posts to the value of one of the custom field of the posts?
- Problem with revisions only returning four results
- Adding Custom Metadata to my Archive/Posts page
- How to improve my non-unique metadata MySQL entries?
- Saving Custom Field that includes Quotation marks
- Query against multiple locations within single custom post type post
- Custom Fields Not Showing (ACF not installed)
- Post meta data not showing in frontend, until hitting ‘update’ button
- How to Find List of Available Custom Fields for Theme?
- select user with all meta field and field value. I am use Below Query for this ,So any of know another way to fast query instead of below query?
- update meta field value after
- Custom Fields Not Working In Footer
- ACF plugin and field update
- Echo out custom fields in comments
- Search one custom field?
- Can’t save meta field value if the title not set
- Display Data From This Custom Media Upload Meta Box?
- Save values generated via API as custom meta fields
- Ordering posts alphabetically by meta keys and title
- Adding custom fields to images
- How to save dynamically generated value in post type?
- update_post_meta not working in action hook
- How to query post ids liked by the Author
- how to show this part only in the single post page?
- Display meta data from a custom field within plugin Category Grid View Gallery
- Checking if field is set before comparing with meta_query in query_posts?
- How to check if custom field exists in this widget query
- Only show content slideshow if “slideshow” custom field exists
- If post custom meta data is not set, show normal state
- How do i output images from URL’s added to the same custom field key
- Filter Query Post by Custom Fields(by date)
- custom field with links
- add multiple values (array) to post meta_input
- Site uses wpdb to fetch meta_keys but just displays first meta_key from a page (the post uses the same meta_key “filmmaker” more than once)