You can use below code to add other two parameter as condition.
$args = array(
'posts_per_page' => $postsCount,
'post_type' => $postsType->name,
'order' => 'DESC',
'orderby' => $postsOrder,
'taxonomy' => $postsTaxonomy,
);
$postsOrder = get_sub_field('posts-ordering');
if ($postsOrder == 'post_views_count') {
$args['meta_key'] = 'post_views_count';
$args['orderby'] = 'meta_value_num';
}
$query = new WP_Query($args);
Related Posts:
- When to use WP_query(), query_posts() and pre_get_posts
- How to get an array of post data from wp_query result?
- How to only display posts whose meta_value field is not empty?
- WordPress Pagination Not Working – Always Showing First Pages Content
- Whats the difference between post_limits and pre_get_posts?
- WP query taxonomy input differs to output?
- How to add taxonomy filter on the query fly?
- Query WooCommerce orders where meta data does not exist
- How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?
- What exactly does the ‘s’ parameter search for in WP queries?
- WP_Query min and max values
- post_type is ignored by WP_Query when ‘tag’ argument is included
- get_posts not finding argument: post_name
- get query’s query string
- Show only oldest post by author
- assign 2 $args to one wp_query
- WP_Query OR clause for tax_query and keywords
- Calling a custom excerpt function in a local loop
- Dynamically Override Fancy Title – Part II
- Transient pagination not working properly
- How to run query inside a class with namespace?
- Which filter/action hook gets triggered after a query has been performed?
- Modify existing query and change order of posts
- Why query_vars get altered in WP_Query Object?
- Sticky Post default functionality with WP_Query is ignored when using AJAX
- tax_query OR with empty result returns all posts
- WP_Query Order by Specific Post ID First
- Custom Query – show first post twice?
- Using one WP_Query object within the loop of another WP_Query object
- Order by slug in get_terms with multiple taxonomies
- Is there any advantage of using default WordPress Search instead of creating a custom one?
- How to access WP database inside ipn.php? [duplicate]
- is_tax() function not working as expected
- Getting the current post number / make posts increment
- Optional Meta Query
- Multiple If Else with WP Query in WordPress
- Serve specific “template” page at any URL that ends in its slug
- WordPress pagination not working using WP_Query
- posts_per_page not working for first page of pagination
- Advanced ordering of query_posts
- Add class to first post in custom loop using post_class filter
- echo a specific meta_key queried through a custom post
- WP_Query with meta_query dosen’t return results
- Get latest post revision with wp-query
- How to show more post at a given category?
- WP_Query returns posts_per_page + 1 every time
- Custom WP query with polylang term
- All posts returned when author of 0 is queried
- Merge two search functions for custom post type
- Filter Custom Taxonomy Posts
- WP_Query – Accessing MetaValue from Query Result
- problems with comments_number()
- Trying to retrieve random post, getting a page
- get_the_terms – but only show 4 Posts
- Does WordPress have something like Drupal’s DB API?
- PHP – Loop custom post type categories within jQuery Tabs
- WP_Query by keyword OR post tag
- How order posts from category by date and comment count?
- Get a list of ACF Repeater-Fields as array
- query_vars empty when using custom url with custom rewrite rule
- Get query results with a page title
- Show single posts date, in a page of posts
- Post archive for certain post format
- Compare “Main” post ID to ID inside wp_query loop
- Attempt to display site authors in a carousel – User Image not Outputting inside li tags
- Add AJAX “Load more” on custom query block
- problem with the loop
- Order WP_Query by meta_key priority when ‘OR’ relation used for multiple meta values
- Why my query is not “Main_query”?
- Filter sub-category from checkbox form
- Facing problem with tax_query results
- How to add a “base” filter for all posts visible to visitors on the site?
- Pagination of custom page with custom fields query
- sanitize_post() is not sanitizing Post Object
- WP_Query() not filtering posts for category
- wp query search multi terms
- How to get top rated posts using wp query?
- Unusual high query of user meta data
- Woocommerce featured products query no longer working
- add action for wordpress query at a specific position
- How to query wordpress with array of meta_values?
- Updating an intensive wp_query result once daily
- Custom WP_query and integrating into theme file
- Empty ‘terms’ in ‘tax_query’ returns an empty array
- Get newest value of an array
- Filter custom post type by custom taxomony
- ordering and optimizing functions
- Why does order ASC break offset in WP_Query?
- new WP_query using custom fields
- Having Trouble Running Query From Shortcode Using Tribe’s Events Plugin
- Change ‘post_modify’ with a query
- An archive page without post format (just standard post)
- WordPress Query Returning Every Post
- Pagination showing same posts despite changing page
- shortcode with $atts with strange results
- Query custom post types by meta field in a term from custom taxonomy
- Show number of posts AND number on current page (cannot make it work)
- How to include custom fields in wordpress search
- Extend search query to search meta keys values based on search string
- AJAX multiple search boxes not merging with array merge