Here I put orderby attributes as option values – date and title.
<form method="GET">
<select name="orderby" id="orderby">
<option value="date">Newest to Oldest</option>
<option value="title">Alphabetical</option>
<button type="submit">Apply</button>
<form>
On the same page you can recieve select value and set as orderby attribute
$wpb_all_query = new WP_Query(array(
'post_type'=>'post',
'posts_per_page'=>-1,
'order'=>'ASC',
'orderby'=> esc_attr($_GET['orderby'])
);
Use your loop to show posts
Related Posts:
- change the default order of posts only for specific categories
- Query category-specific, paginated posts and allow viewer to change sort order
- How to modify this function to exclude also the post belonging to a specific category?
- Inject post (from specific category) between posts in Loop
- Build a content and excerpt grid loop with paging and options for # of posts
- Alter query on edit.php
- how to display active, upcoming and past event with featured listing with pagination
- Count number of published posts by type
- Get taxonomy terms only of the WP_Query current posts
- Exclude posts from homepage having a specified tag
- Hide post if matches current month and year
- Can’t search posts using WP_QUERY inside AJAX Function
- How can I use wp_query to show all product data using just the products ID?
- Displaying the last post on static homepage
- Why WP_Query(‘showposts=5’) shows only 1 post?
- Sort query_posts for Parent Pages to menue order or the count?
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- How to store post ID’s in cookie or session to display the same posts later
- Sort by page information by Ascending Numbers
- Counting Search results, and displaying the offset per page
- How to get post ID in a Page?
- WP_Query: getting posts where custom field exists
- Array to string conversion on array_map
- Store metakey value as an array
- Increment paged on WP_Query
- Order BY Most Liked And Published Between Previous Week Monday And Next Week Monday
- Modify main query before it run without pre_get_post
- Do not duplicate posts with multiple categories in multiple loops
- array_rand not working correctly?
- WP_Query() load selected post
- Saving a post ID to use in a form elsewhere on website
- posts_nav_link pulling in multiple post types
- Remove Post if Advanced Custom Field is checked to fix paging
- Wp Query : Order by distance lat,lon
- search.php to search only the post title
- posts_per_page displays only 2 posts instead of 4 posts
- Is there anyway I can call the year once?
- Query on a repeater date (acf)
- Need to show 7 posts from actual date
- Check the database for a postmeta field
- Getting info about selected posts using one WP_Query
- How to display last whole post on the homepage
- Only Get A Certain Number of Posts From WP_Query
- Create a hierarchical loop at predefined markup requirements
- insert thumbnail image from php script
- Sort / Filter Queries
- Weird Behaviour: Not all WordPress Posts appearing
- List of child pages fetch next results at link click
- Automatically create a loop for post ID
- Why does WP_Query show only the same post even with different categories and endwhile?
- Custom query_posts() parameter
- Posts sortable column not sorting properly for custom field numbers
- Does wp_query and query_posts affect website performance? [duplicate]
- Pagination in category.php not functioning
- /page/2/ redirect to 404
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- How do I exclude the current post from the upcoming post query
- How do I use WP_query with multiple post IDs?
- Disable Attachment Pages Completely
- is_page() not working from within a plugin
- What is the most efficient way to search users by their display name?
- Passing JSON data from WP Query into AJAX causing NULL errors
- How to order posts by modified date without using ‘query_posts’?
- How to add 2 posts under another post? Formatting should be intact
- Function to show random posts from a category
- How to get 2 or multiple custom post types in wordpress functions.php
- How to securely provide a $_POST var in WP_Query with PHP 7?
- Create WP_Query to search for posts by their categories or their parent/child categories
- Sort posts by custom fields value using dropdown menu
- Unreadable pagination
- how do I get a specific post from a post with a subcategory in WP
- Open post-content in archive page in a Modal box with bootstrap
- List authors with the last post title and order by last post date
- How to get all author posts outside of author templates
- WordPress query_posts by tag doesn’t work anymore(?)
- Automatically add images to a menu
- How to display SQL query that ran in WC_Order_Query?
- On what hook can I get the queried object’s final state?
- Post not populating for custom post type based on category selection
- Infinite Loop – WP_Query
- Wrap posts p tags in div
- WordPress SQL JOIN query
- WP_Query and help with the loop for magazine front page
- Sorting the Loop by Taxonomy Value
- Generating 10 000 WordPress posts using PHP and avoiding Server Timeout error
- If Post Published Date or Modified Date is 1 Year or Older, Display Notice on Post Page
- wp_Query with mutuplea values returns all posts
- How to display sticky post always at the top (before regular post) in wordpress?
- When working with a post, almost all wp_postmeta are deleted
- How to get the posts that my following users are liked?
- Displaying POST content with HTML tags and all
- wp_query args with relation
- Pagination in WP Queries
- direct query to post_meta table
- Can’t put a hyperlink on Featured Post’s Image
- List sibling pages widget, exclude current page
- wp_query select if have comments
- Ajax Load More or View More functionality for woocommerce category layout by template overriding
- a problem in class in class-wp-hook.php
- Count custom posts type and filter by tag