You will have to use 2 queries, where in the first loop you should use:
$args = array(
"post_type" => "post",
"post_status" => "publish",
"orderby" => "date",
"order" => "DESC",
"posts_per_page" => 20,
'post__in' => cat,
);
(The Query)
And in the second:
$args = array(
"post_type" => "post",
"post_status" => "publish",
"orderby" => "date",
"order" => "DESC",
"posts_per_page" => 20,
'post__not_in' => cat,
);
(The Query)
This should work because the first loop will take only the posts from cat and the second loop all others, and the first loop will always stay on top, Altought I don’t know if you won’t have a problem with the paginations that way, you should also ensure that you reset the post data with wp_reset_query(); for example.
Related Posts:
- When should you use WP_Query vs query_posts() vs get_posts()?
- How to query for most viewed posts and show top 5
- WP_Query vs get_posts
- What is the most efficient way of querying posts based on visits and date for current day?
- Custom WP_Query order by post_meta and (author) user_meta
- WP_Query for WooCommerce Products
- When should you use wp_reset_postdata vs wp_reset_query?
- Perform query with meta_value date
- Order posts by tags count?
- Add and in the header while looping over custom query in page template
- Which custom query am I in and how can I access its properties & methods?
- How to speed up wp_query, took more 5s to run against 100k posts
- WP_query category__in not working, only pulls from first category
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- How do you query wordpress posts using a math formula between multiple meta field values?
- Custom Post order for homepage
- Page navigation doesn’t show when query category
- How To Get Some Data From WordPress Database Using WordPress $wpdb Query?
- Meta Query for specific months
- Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX
- Different string for specifed post type on posts listing at homepage
- if/else on custom query gives 200 OK when condition not met?
- Minimize database queries to user tables?
- Query all published post AND attachment with specific mime type
- only delete post within query / for each statement (front end)
- Add quicklink to in the Admin posts page where I can query by a meta_key
- Get all products which have both product category
- unable to retrive parent page information
- How to detect if query is runned from widget?
- How to display user order by role
- How to use the query hook/filter?
- WP Query related posts by tags
- Order by summing multiple values
- Check if loop has any categories?
- How to get list of posts from permalinks?
- Is there a reason why Pages are not publicly_queryable?
- Check return value of get_posts
- Exclude some authors from query
- Query only the posts with a post format of “audio”
- Transient api Caches confused
- How can I override one post and make it display content for another post?
- pre_get_posts – Trying to get property of non-object warning
- Get multiple users with meta value in one query and populate WP_User class
- Get a list of posts by specific category
- How to check the array values, what WP_Query has brought to me?
- How to add custom meta to ‘pre_get_terms’?
- Shortcode for custom query not returning results when attributes are added
- Should I reset $wp_query?
- Update query for wp_posts and wp_postmeta
- Get specific ACF key and value from all posts – no access to DB
- I am officially missing something about transient posts
- Start Query from 2nd Post without offset
- Display upcoming events in the next 30 days by querying posts with timestamp in custom meta
- Post incorrectly excluded when using “category__in”?
- Display posts ONLY from the current logged in user and current week/year/month Elementor posts
- Any way to use FETCH_KEY_PAIR with $wpdb?
- Adding nofollow to all the post links in get_posts with pre_get_posts or WP_Query
- Meta query orderby meta_value_num sorting by role first
- Query against multiple locations within single custom post type post
- How to query users by post count no less than 10
- WP Query. Ordering posts by another post types meta
- Add to search posts query array with post IDS which will appear first
- How to make a search query if not found in post table then search in postmeta table?
- WP_Query about meta_key and its array value
- Create global array to compare inside a query
- Ignoring ‘a’ when sorting posts
- how to show more than 1 post into three columns query
- Using the same WP_Query for shop and widgets in WooCommerce shop
- How can I get all the posts that are related with a specific taxonomy term?
- Custom query for tag and custom tag from 2 post type
- wpdb get_results() returns only 2 rows
- Query posts in current category but not attachment format
- Filter posts/pages by user_role array
- WP_Query secondary query failing
- Search Functionality broken by the wp 4.2 update
- Issue attempting a wp_query_posts with tags
- wp_query – Modify $query to include duplicate content
- Optimising specific Query with ACF meta objects
- How to get several fields from wp_query?
- add_query_vars does not work
- Pagination not working with WP_Query (creates links but no page)
- Divide WP_Query posts by date & post type
- Retrieve posts in custom post type and specific taxonomies
- Query Posts by date range with fixed beginning and end
- New WordPress WP Query using posts from certain categories
- Custom post types loop on a page template
- Get the number of rows from $wpdb->get_results not working
- Parsing External Table Arguments
- Get Child Custom Post Content on Single.php?
- difference between methods of query
- Query posts by meta value and sort by another meta key
- How much does $wpdb->prepare(), then $wpdb->query() VS straight $wpdb->query(), can slow down the load time of whole page
- how to use transient method?
- Pre_get_post on CPT archive page
- Get posts that were most recently tagged
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- How to get posts that have certain meta key value and order based on another meta key’s value
- Filtering custom post type list in admin by custom meta key/value
- How to use meta_query to retrieve posts from multiple custom post type
- Rewrite URL custom search query