Was able to solve this by first registering the custom query var.
https://codex.wordpress.org/Plugin_API/Filter_Reference/query_vars
And then next I used the switch
function:
global $wp_query;
switch ( $wp_query->query_vars['filter'] ) {
case 'random':
$recipe_args['orderby'] = 'rand';
break;
}
Related Posts:
- Sort posts by category name and title
- ajax category filter
- Display posts the match taxonomy term linked from wp_list_categoies?
- WordPress 4.9.5 PHP intermittent warning trim() expects parameter 1 to be string, array given
- Merging multiple wp_query objects
- Query causing load because of SQL_CALC_FOUND_ROWS post counting?
- Using custom meta_query with relation not working as expected
- Nested query inside Logical operator OR not working in meta_query
- SQL Statement generated by WP_Query not producing expected results
- Only show first post to match certain criteria within WP_Query
- WP_Query on different site in a multisite setup
- Best practice for multiple queries on page
- How to order a post type with meta_value_num and if meta_value_num does not exist then order by date
- How to user WP_Query to lower the number of queries
- Exclude post on loop by multiple meta key value
- how do i combine keyword search and taxonomy in a WP_query $args array Worpresss [closed]
- How to find out what “Blog pages show at most” is set to [duplicate]
- difference between $wp_the_query and $wp_query? & getting the values properly [duplicate]
- Ignore/Skip default value on orderby menu_order?
- WP_Query order by date in meta_value
- WP_Query pagination not working in admin area
- Custom Field sort not working (WP 3.8.1)
- Get post ID’s from one query and exclude from another
- Sanitizing search data for use with WP_Query
- WordPress Query is taking more then 20 second and stuck on creating index
- Modifying raw $_POST data early in the lifecycle
- How to query for custom field within Gutenberg block from outside of that post? [closed]
- WP_Query mixe post and page attributes
- get_query_var returns null
- post thumbnail not showing up with shortcode
- Wp query orderby ‘title’ doesn’t work
- Meta query with JSON value
- Prevent duplicate post from dynamic multiple loops
- Get meta info related to current post
- Can I count matches without doing a query?
- Store sticky post’s ids in a transient
- Get attachment by meta_key value
- Complex WP_Query order request: DESC by day, but then ASC by time
- How to detect if query is runned from widget?
- Using meta_query with multiple keys and compare values
- Woocommerce query all products and categories
- Add “Category” to Mysql Query
- Can I set my WP_Query to be a Main Query?
- Sort wordpress custom posts based on meta value
- How to use external API content in place of WP posts using $wp_query?
- Is it possible to set specific posts to show first in a query?
- How to make search for posts using get method?
- Is there a reason why Pages are not publicly_queryable?
- Exclude some authors from query
- apply custom where to the default $wp_query
- wp_query serialised array
- Conditional operator OR not working with custom fields
- How to add custom meta to ‘pre_get_terms’?
- How do I check if an article is popular this week?
- Using Transients
- Should I reset $wp_query?
- Exclude a Woocommerce product from WP_Query
- Sorting search results with custom dropdown
- Posts query according to meta box date
- create metabox to activate slider
- Expecting statement error from php loop using ACF plugin
- problem with loop
- How do I sort this custom list of sticky posts
- WP_Query will not display draft posts
- All Posts Have The Same Comments
- Trying to get property of non-object in: $wp_query
- How do I get the content of a custom instance of WP_Query?
- Change post query onclick
- Display upcoming events in the next 30 days by querying posts with timestamp in custom meta
- Searching not only by post name but also category
- WP_Query, Paginate by Custom Field
- Query post and sort by custom value calculated with custom field on cpt
- Block internal search queries with pre_get_posts and regex rules
- Search Exact on WordPress – Relevannsi Solution Not Working
- WP_Query() not working as expected
- How to sort store location by specific category order in WP store locations
- Posts per Page not working
- Trouble with serialized metadata
- Get authors list and sort them by recent posts
- Custom filter from post meta
- Is there documentation for objects returned by WP_Query?
- Multiple wpostmeta.meta_key
- Custom post type loop error: Trying to get property of non-object
- Search Field that allows options of “Match any keyword” or “Match all keywords”
- Saving custom fields for WP_Query to retrieve
- Getting the last X posts, but in ascending order of time
- Modify query to exclude certain ids and certain parents and its corresponding children
- How to fix pagination for custom loops on front-page.php
- Show more than one post on the main page excluding certain category
- How to make a wordpress loop file that displays posts based on certain conditions
- WP_Query with MetaQuery issue
- Cannot order by in WP_Query
- How to sort a WP_Query array by post_name after an array_merge();
- Comment count same for every post in homepage WP_Query
- WP_Query breaks pagination
- wpdb LIKE request shows all database data
- query_vars category_name only display one catgory out of multiple categories
- Incorrect posts displayed on category page
- I want to capture the last day’s (today) posts in a category in the numbered order in acf
- How do I have multiple metaqueries inside one wordpress query