Use pre_get_posts
instead..
function my_archive_query_override( $query ) {
if ( $query->is_archive() && $query->is_main_query() ) {
$query->set( 'orderby', 'rand' );
}
}
add_action( 'pre_get_posts', 'my_archive_query_override' );
For that user selectable part, you can use AJAX to accomplish that.
Related Posts:
- Query multiple custom post types in single loop
- How to get to a specific position in wp_query?
- How to add div blocks after certain set of post
- Inject post (from specific category) between posts in Loop
- Build a content and excerpt grid loop with paging and options for # of posts
- How to create a WP_Query to search the Title or Tag?
- Alter secondary loop to exclude posts from current page category
- Specific Loop For 2 Within Each
- Display related products with custom output
- spliting posts into two columns
- have_posts() execution failure
- Why is variable not working on custom sql query using wpdb?
- Using foreach loop breaks
- Create WP_Query to search for posts by their categories or their parent/child categories
- WP Query with custom Shortcode
- Increase offset while looping
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- WP_Query fails despite having 1 post
- unable to use ‘new WP_Query’ in AJAX call
- wp_query get the 2nd post
- How to get post ID in a Page?
- Display an image if odd number of posts in grid
- get_the_ID() in the footer returns wrong value
- WordPress query undefined offset in loop
- Issue with custom loop in Archive page
- How to display SQL query that ran in WC_Order_Query?
- Get all posts as an array ID => Name
- How to hide posts of a specific custom category in WordPress?
- WP_Query multiple post results
- Do not duplicate posts with multiple categories in multiple loops
- Infinite Loop – WP_Query
- Dividing the loop to style post differently
- Limit tags shown in post
- How to extract information from a wp_query result?
- Echo array value
- Search.php gets metadata from first post
- the_post(); prints out style text into my HTML?
- Search AJAX Filters – Multiple Query Loops Into One Loop (Optimization)
- Wp Query : Order by distance lat,lon
- How can I modify this code to make the search box include tags and meta
- Display articles with a different template in the home page | Solved |
- in_array not working on dev server but works on localhost
- How to display sticky post always at the top (before regular post) in wordpress?
- wordpress query returning unexpected results
- Making list of posts with chosen description
- Query doesn’t display text data with apostrophes
- My query keeps looping infinitely ! how to stop it?
- Efficient way of querying for a “fallback” post?
- How can I display a query in a page?
- For each 3 posts, show a different post type
- Add post class in custom loop (WP_QUERY)
- Create a hierarchical loop at predefined markup requirements
- Problems With Query and/or Template Part and/or PHP
- Advanced Taxonomy query, with 3 post types
- Why does a meta_query break this WP_Query?
- Does wp_query and query_posts affect website performance? [duplicate]
- WordPress post pagination on custom template not working
- Pagination in category.php not functioning
- wp_query on search results page showing all results every time
- Show post like this image in my newssite [closed]
- Three different queries on same page
- 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 display WooCommerce products in my query to rows of 3?
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress
- Sorting Posts | Alphabetical Order
- Storing Array from returned database query and using the array in a new query
- Changing layout with wp_customise
- How to use an associative array in post__in with WP_Query?
- get author_name from queried post
- Exclude posts based on meta value
- Query if audio attachment AND/OR custom field
- post thumbnail, conditions, else wont work
- I’m trying to create an array with a foreach loop, but the array only stores the last item [closed]
- WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank
- Array to string conversion on array_map
- Target post_date_gmt if it’s empty or not set
- Why my loop isn’t working? [closed]
- Passing an array into WP_Query as a variable
- Custom query vars filters problem with pagination
- WordPress meta_query >= &
- Remove Post if Advanced Custom Field is checked to fix paging
- WP_Query: How to get results from both meta_key options?
- Passing in MySQL prepare statement parameter separately throwing error
- Load more posts using AJAX based on posts inside WP_Query
- posts_per_page displays only 2 posts instead of 4 posts
- Where does php code to load data go?
- Paged WP_Query is quitting on page 3
- Get Child of Child Pages in custom Menu
- Latest posts feed with a specific post always first
- Why does a header location on admin_head remove the query var I’m setting in the location?
- Get featured image outside the loop using foreach
- Loop 1 user randomly
- Query seems to be duplicated
- Remove the_content From Loop
- Adding if statement to content for homepage
- Tables not showing divs and loop/php items
- How to insert a variable into a query parameter?
- How to create a loop that will display one post and stop?
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise