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
- Exclude first post from wp query
- Category Attachment Pagination 404 Error on 2nd Page
- Query posts distinct authors
- How to get previous 10 days post from a specific date – WP Query
- Handling error states with admin_post
- WP_Query | Help me create a search term with an ‘OR’ relation?
- Archive listing of posts by publish year (multiple years)
- Why does “get_option” pull in the older value in options.php, rather than the newer value, on submission of a form?
- Search widget breaks when using multiple loops?
- WP_Query use for a filter with multiple Taxonomies and Terms
- Make custom field meta not display if there is not data in it
- Display related products with custom output
- How do I dynamically generate args for wp_query?
- Get_the_author doesn’t return author name
- list posts and wrap them alphabetically A-Z
- Order posts randomly, not by date
- Accessing post->ID outside of the loop for listing child pages
- Working with query_posts ( arrays and query strings)
- Get Current User Id Inside a Loop Returns 0 For a Shortcode
- Custom page archive query by url var calling page twice on one of my custom queries?
- Reset Popular post query?
- How to query for posts with a null or blank post_name?
- WordPress pagination not working with search page
- Trying to add attribute to my posts’ featured image
- WP Query with custom Shortcode
- Using loop pagination on single.php
- Get latest 3 posts from multiple CPT in one query
- Sort custom meta column by other meta value
- Add more button if more 8 items
- Post + form + action + results on the same page
- Post repeating with infinite scroll
- Error display post thumbnails for previous and next post
- echo var into wp_query
- Query function not executed between element [closed]
- get value from get_post_meta then reuse it in another get_post_meta
- Build A Custom SQL Query for WordPress Search
- Only display notification on single post
- Transfer WordPress Login Session to an Extended Webpage on the Same Domain
- Get posts associated with media attachment
- Why I obtain this WP_Query strange behavior trying to select posts having a specific tag?
- Excerpt all post content Content Same Size without word cutting off
- How do I display WooCommerce products in my query to rows of 3?
- AND and OR in my CPT search query depending on checkbox