You can get all posts by using a meta_query
that gets posts where the key either does or does not exist, and then order on meta key with a secondary order for posts with same value or no key:
$args = array(
'post_type' => 'my_product'
'tax_query' => array(
array(
'taxonomy' => 'my_product_cat',
'field' => 'slug',
'terms' => array( $category->slug )
)
),
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'vip_row',
'compare' => 'NOT EXISTS',
),
array(
'key' => 'vip_row'
'compare' => 'EXISTS',
)
),
'orderby' => array(
'meta_value_num' => 'DESC',
'date' => 'ASC',
)
);
$query = new WP_Query($args);
Related Posts:
- WP_query parameters for date range
- ACF: post query, hide duplicate values [closed]
- Performance considerations – postmeta table versus new table for custom posts with foreign keys?
- WP-Snap too slow (caused by WP_Query?)
- WP JSON REST API (Ryan McCue) how to query posts with specific meta data with ‘AND’ relation?
- Creating two database tables via plugin
- Query Posts by Custom Field ‘Price’
- insert data in database table from plugin with WP3.1
- Thumb rating for wordpress – top user
- Comparisson between date() and a date from wp_postmeta
- How to extract images of post and pages excluding header and logo image in wordpress?
- How to count number of records found in a database table?
- Fatal error: Uncaught Error: Call to undefined function get_userdata()
- Advanced Custom Fields query
- Can I run multiple queries with $wpdb->prepare?
- greatest() function returns undefined property
- How use %like% in sql statement wordpress
- WordPress logo upload option in theme panel
- WP_Query ordering numbers as letters
- FacetWP group listings by custom field [closed]
- how do i remove posts from a WP_Query so the pagination is right?
- Accessing post’s meta data based on user’s click of a post
- WooCommerce shop page orderby [closed]
- Call to a member function have_posts() on a non-object on normal loop
- Get posts from WP_Query and format them on admin_head
- Not getting author rank when using return
- How to query the custom fields by language?
- How do I “get the next 10 posts after post_id == x”?
- switched from query_posts to WP_query, not working now?
- Multiple instances of nivo slider plugin
- How to change this WP_Query to get all ProductIDs and not only specific one?
- How to call WordPress function other files
- Insert content of a post into another
- WP_Query and NULL meta keys
- how to use in custom single.php template using php?
- WordPress page and plugin list using sql query
- Using AJAX to generate front end / viewer end pages
- background images WP Supersized on homepage
- WooCommerce search products between price range using WP_Query
- How to Loop Through all Posts and Count Attachments using Get Media Attachments
- Render content of multiple pages and their descendants
- How to get a list of bundled products using wp_query in woocommerce
- WordPress Apply filter in plugin causes 500 internal error
- Meta query for comparing two dates
- Error in pdf generating plugin using FPDF
- Return multiple values in a shortcode attribute
- Loop returns the current page’s permalink and guid instead of the post in the loop
- Add user meta after a user has registered and logged In [closed]
- How to get CPT category checkbox list and show post of selected(multiply) checkboxes via ajax?
- BuddyPress activity on edit post for a CPT
- How to display a number of posts based on a Advanced Custom Field (ACF)
- Delete data from custom table when deleting a post
- Pagination not working
- How to find the WordPress Nextgen galleries which are not used in WordPress posts?
- Adding CASE in WP_Query
- Searching a tab/space delimited text file based upon form criteria and returning a ‘record’ into a word press results page
- Woo-commerce Update price as a Bulk from My offline software export
- How to search post titles with whole words only, but not the exact word only?
- Trying to get property ‘ID’ of non-object in /wp-includes/class-wp-query.php on line 4044
- Use get_pages() before another plugin modifies it
- how to display recent post by category on home page
- How to Join wp_posts & wp_postmeta table using custom query
- What database state changes happen after a post is manually “updated” with no changes?
- any word search WordPress
- Warning: call_user_func_array() problem can anyone help with it?
- Fatal error: Uncaught Error: Cannot use object of type WP_Error as array in /../plugins/rm-payment.php
- adding dynamic/multiple slug values in ‘option_none_value’
- custom post type get_posts() function not work
- Checkbox field that add a subscription product and change prices of other products in checkout and cart page
- Only return taxonomies that are linked to a category & product
- How to add specific posts to specific pages in WordPress?
- How to use information from the database in the front-end?
- User Following System
- How to fix slow comment query?
- ACF Query result in a new td (echo)
- Multiple Meta key in search
- wp_schedule_event function reference
- History of page, interval of years
- How to insert variable which contain array value in wp_options table?
- how to repeat taxonomy in different places on wordpress
- Trending Tags based on post views
- Plugin does not create a custom table upon activation
- Action hook “wp_insert_post” works but not for last imported post
- Second foreach loop breaking (Posts2Posts)
- Ger posts from similar tags and categories
- wp_query for more fields plugin
- WordPress filter function using query modifications
- wpdb get_var is not returning any result (verified mysql query returns only one value)
- WordPress Meta Query: Relation is not working correctly
- WordPress ultra slow if I click on posts?
- Insert data in custom table during new post creation
- single.php fires more than once after clicking on any post to view with different post id each time
- WordPress plugin not eching popular posts
- Include subtitle display to slideshow
- Checking url from plugin [duplicate]
- Browser Cache causes ‘Orderby=rand’ to return the same posts
- ‘Active lotteries’ only custom query for woocommerce lottery plugin and elementor
- I want to display data last 7 days with date wise in chartjs?
- Order custom post type by posts with most likes first
- Accessing Correct Database to Create REST API Endpoint