Finally I’ve decided to use custom sql query with get_results method.
$query = "SELECT SQL_CALC_FOUND_ROWS p.*, IFNULL(m2.meta_value, p.post_date_gmt) as zen_date
FROM {$wpdb->posts} p
LEFT JOIN {$wpdb->postmeta} m1 ON (p.ID = m1.post_id AND m1.meta_key = 'is-exclude')
LEFT JOIN {$wpdb->postmeta} m2 ON (p.ID = m2.post_id AND m2.meta_key = 'is-push')
WHERE p.post_type="post" AND p.post_status="publish" AND m1.post_id IS NULL
GROUP BY p.ID ORDER BY zen_date DESC LIMIT 0, 50";
$posts = $wpdb->get_results($query, OBJECT);
foreach($posts as $post) {
setup_postdata($post);
// do something
}
If somebody suggests something better, I’ll be glad to accept that answer.
Related Posts:
- How to query serialized array by comparing greater than (>=)?
- Working Bootstrap Carousel Conversion to WP – Technical Questions
- Query posts by Author and/or by Tag
- Advanced Post Display/Pagination/Ordering
- The next_posts_link() works only with original $wp_query
- Query *only* sticky posts
- Skipping first 3 posts in wp query
- Accessing the post content with WP_Query
- Most viewed post for the last 2 days using WP_Query
- Adding Post Counts to Menu (Nav) Programmatically?
- This AJAX Code Doesn’t Work – Looking for elegant solution
- Get only modified posts
- Possible to create a permalink to sort with meta_key?
- How to output comments number of a post per day?
- Should ‘setup_postdata()’ be reset with ‘wp_reset_postdata()’?
- If specific user role then sticky post
- Display posts with comments closed, with pagination?
- posts_per_page doesnt work
- What Is meta_id In wp_postmeta?
- Blogroll – Different layout for first post
- I want to query posts in monthly basis
- Loop through all product posts?
- Custom WP_QUERY $args
- Improving WP_Query for performance when random posts are ordered
- Why won’t my taxonomy query show up?
- Limiting the number of posts in WP_Query leads to unexpected result
- WP_Query with ajax handler returns the same posts
- Why WP_Query(‘showposts=5’) shows only 1 post?
- How to insert 2 args into 1 Wp_Query for a slideshow
- WP Query – Posts Per Page not working in combination with category__in
- How to do set post permalinks using 6 digit random unique function?
- how to change the number of posts returned in a specific loop without making it global?
- posts_per_page option limits the number of Gallery items
- List authors with the last post title and order by last post date
- How to order posts by meta_value and title
- Nested WP_Query breaking loop
- Why Query is returning empty array?
- meta_value timestamp older than now
- Get posts with multiple categories
- Do not show children of a category
- Print out last 3 blogposts
- Query for first 3 posts to change the look and feel
- Getting blog pagination to work on page set as front page
- search blog posts by author first name and or last name
- unique post in “$args” of wp_query display more than one post
- Display current post position in Elementor Posts widget
- How to give classname to post if post has no content?
- Custom wp-query in wordpress rest api
- posts_per_page returning only one post
- Need to know custom code to display random and most viewed posts in wordpress posts and pages
- How to retrieve certain number of images from a wordpress post?
- WordPress post filter menu
- How to display post list in a table layout (multiple queries in single loop)
- Not all posts showing in query
- WP_Query custom field pass the post id
- Link to date_query results in WordPress
- WordPress query portfolio posts
- Current and next month posts
- Get latest author posts inside the loop
- Same post appears in related Posts?
- Display 3 posts with different HTML markup using a loop
- How to show multiple posts thumbnail, title and date in widget
- WP_Query outputs wrong post in custom post type
- how to show comments only author which send own posts in wordpress
- Group first, 2nd, 3rd, etc posts by category terms
- Manipulated offset and pagination, can’t display last post anymore
- Function is printing twice – any suggestions?
- How to sort WP_Post Object array by object field in php?
- Order by meta_key field in WordPress not meta_value field value
- How to display particular set of wordpress post on a webpage?
- How to create page with post content in it?
- How to remove a post from results by ID after query?
- How to use two query result together in one loop
- show loop id post , only first id can read
- How to get value of a selected option from select tag and use it in WP_query to filter posts?
- Counting Posts by Category
- show image gallery in archives or category page
- filter posts based on menu_order
- Show 5 posts and than 3 posts offset with pagination
- Change archive results based on GET request
- wp_query args with relation
- Wp_query loop is not working as it should
- Show all posts from the tags without having to set all of them
- Is it possible to query a category with specified posts?
- Creating Ordered Query using Meta_key
- Is there a global page/post/product/anything ID?
- WordPress loop uses unmodified posts array, why?
- wp query custom orderby not custom field
- Show posts between two Custom Fields date
- Query to get data of a post, if in category?
- Order posts by custom field
- Why I have this strange behavior when I try to exlude the featured post from posts visualization?
- Remove duplicated posts in the loop if post has more than one category
- Why I getting only 1 post?
- The next_posts_link() works only with original $wp_query
- wp_query posts sorting doesn’t work
- Limit amount of pages shown in pagination within wp_query
- First post in loop displays twice
- Get related posts matching most of the provided tags using WP_Query
- WP_Query post_tilte search in posts table