The standard query for posts uses orderby => 'post_date'
and order => 'DESC'
. The best candidate for arbitrary sort of posts would be orderby => 'menu_order'
and order => 'ASC'
. The menu_order
is not generally used for posts but it is safe to be used. As suggested by Pieter Goosen use action hook pre_get_posts
:
add_action( 'pre_get_posts', 'your_function_name' );
function your_function_name( $query ) {
if ( !is_admin() && is_home() && $query->is_main_query() ) {
$query->set( 'orderby', 'menu_order' );
$query->set( 'order', 'ASC' );
}
}
The above is for front end. For back end use visual drag and sort jquery and update the database. You can check the logic in pageMash plugin.
Related Posts:
- Manually set global $post vars with an ID, in order to use template tags
- Is it possible to define a template for a custom post type within a plugin independent of the active theme?
- Ways to have multiple front-page.php templates that can be swapped out?
- Output before and after the loop
- Define Function in functions.php or plugin and call in theme loop
- How can I let users to access plugin functions based on roles?
- Template for custom post type shows all posts instead of just one
- Fastest way to loop through all posts?
- How does WordPress ensure plugins run at the same time and how does it solve a plugin’s dependency on another one?
- post expire after x days
- Can’t get custom posts of taxonomy to show
- Trying to count the total number of paragraphs inside a blog article
- Installing WordPress only for a separate page – ‘mydomain.com/blog’
- Display content from custom post type if match to main post category
- unregistered user can write in blog page – possible? how to?
- how do i remove posts from a WP_Query so the pagination is right?
- Portfolio + Blog: multisite or plugin?
- Override global query results without hooks
- Use wordpress functions in another PHP file
- Fetch Children of Grouped Products Inside WooCommerce Product Loop
- Insert content of a post into another
- Problem with the Loop – want to limit the access to three free articles
- Is there a PressThis that doesn’t hotlink?
- Get User_id outside wordpress,
- Is it possible to send blog posts via email to subscribers?
- Calling the_excerpt from inside a plugin template file
- Recent posts per category loop?
- Import Instagram post to WordPress blog post
- How to replace website?
- Bulk update wordpress posts
- How to get a list of bundled products using wp_query in woocommerce
- Where to find the code used to render a page that has a shortcode and a template defined?
- Loop in elementor custom widget not working
- get_users(); Is an Undefined Function When Used in Cron Job
- Blog previews on custom page with more buttons
- Customizing a blog page layout
- Trying to add_action in a loop
- Loop returns the current page’s permalink and guid instead of the post in the loop
- Get post content from outside the loop with plugin shortcode usability
- Price comparison table based on Custom Post Type?
- Show related posts based of current ACF field name in a single page post (a loop within loop)
- Remember the Meta Value With Radio Buttons
- Output after specific post in the loop
- Plugin is creating posts twice
- Polldaddy doesn’t show up on own theme
- Add custom PHP and HTML to the_content()
- Multiple images per post – Show random image elsewhere
- How to modify the Loop from a plugin (instead of a theme)
- Add posts from other WordPress blog to the current one
- i need to make custom cron_schedule with custom interval time as a parameter into a custom payment gateway plugin wordpress
- How to add a “Who’s who” on a wordpress blog post?
- How page with random php file with query params generated
- Can’t add new plugin or themes on a wordpress multisite network from the primary site as administrator. Error: ERR_TOO_MANY_REDIRECTS
- How to fix blog article view and share #’s?
- How to make cover image in post block expand to entire screen?
- How to upload PDF from Front-End and post automatically?
- How to order blog posts by no. of likes?
- Allowing Comments on Posts
- Create post loop that displays pages by cat ID
- Place content inside the Post Loop
- Automatization for automatization
- Cannot reset a loop in a plugin template
- Displaying image from a repeatable group
- Multiselect value in wp_query
- How to Set Limit with WordPress Get Bookmarks Shortcode
- Advanced Custom Fields (ACF) Plugin – Random Image in Sidebar
- ‘all’ hook and add_action issue (class based plugin)
- Fake Single WordPress Post (Page) Loop
- single.php fires more than once after clicking on any post to view with different post id each time
- How do i use postMash to order posts in a custom loop?
- How can I save a setting field with multiple checkbox options generated by a foreach loop on a custom wordpress admin page?
- Getting Post Permalink Outside of Loop Not Working
- Trying to display posts but getting the pages as output
- Why my site loads too Slow? [closed]
- How to dispaly post informations (such as titles) in an admin plugin menu page?
- Outputting custom field query from a plugin to the website header
- Change from blogger to wordpress
- How to display content depending on the Woocommerce Product Category
- Page with redirect
- FacetWP custom display based on post type [closed]
- category_name not working (not showing up in sql query debug)
- Custom plugin settings: clicking “save changes” does not display success message
- Get the current taxonomy product category title in woocommerce
- Custom Post Type causes Page Not Found
- Detect if a plugin was included in a certain page
- how to load tinymce external plugin
- Organising the plugins folder in wordpress
- google conversion code
- How can I create a custom shortcode that will return a custom post type by ID?
- Plugin: Google Analytics for Dashboard error – Timestamp is too far from current time
- Changes not visible when not logged in
- Api external with wordpress
- Activate a plugin via a SQL query
- Set Button in PluginDocumentSettingPanel Content (WordPress Gutenberg)
- Custom Rewrite Rule Removing Query String
- How to get Angular app working in WordPress plugin?
- How can I display a list of only categories which are marked as ‘featured’ in the backend?
- Unexpected plugin_dir_path Output
- Plugin install error: Installation failed: The package could not be installed
- List all posts in a particular page [closed]