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
- How to limit the number of posts that WP_Query gets?
- Should we trust the post globals?
- The next_posts_link() works only with original $wp_query
- Adding additional data to WP_Post object
- Get current post id in functions.php
- Random sort within an already sorted query
- Get first post from wp_query
- WP_Query: Why is sticky post not first item in loop?
- WP_Query offset argument does not work
- Displaying the category name of a custom post type
- Query *only* sticky posts
- Search by Hyphen
- Skipping first 3 posts in wp query
- Exclude drafts in all() view of edit.php
- Exclude posts that only have the ‘Uncategorized’ category [duplicate]
- How do I reorder (pop and push) items from WP_Query?
- Accessing the post content with WP_Query
- Querying post from a multisite network
- How to exclude latest x posts from a paginated query?
- How to know if get_posts() failed?
- Show related posts by category but ignore one category
- post__in for get_posts with a dynamic array
- Keep getting same permalink with WP_Query?
- Reverse chronology of post listing
- Query posts distinct authors
- WP_Query to work with custom view
- How to query posts with current or future date only
- How to get previous 10 days post from a specific date – WP Query
- WordPress Number of Posts Not Changing With posts_per_page
- Most viewed post for the last 2 days using WP_Query
- Adding Post Counts to Menu (Nav) Programmatically?
- Pagination not working on Custom Page Template
- This AJAX Code Doesn’t Work – Looking for elegant solution
- Create new WordPress post [wp_insert_post] based on results of a WP_Query
- Post content being duplicated by the_content();
- Get only modified posts
- How to add posts to wp_query result?
- Posts for next month
- Exclude posts with specific meta_value while sorting by a separate meta_value
- Specific loop in Shortcode
- Sort posts by activity date
- How to add padding between posts
- Possible to create a permalink to sort with meta_key?
- prevent showing posts of an specific category in admin posts section
- How to output comments number of a post per day?
- Search widget breaks when using multiple loops?
- WP_Query only ONE post, won’t work
- How to change bulk post status
- Add few specific post ids to wp_query
- Should ‘setup_postdata()’ be reset with ‘wp_reset_postdata()’?
- Unable to modify(update) posts – Page not found
- Display the latest posts, published in the last hour, with WP_Query
- Replace Main Query With Custom Query
- Exporting Data from WordPress into a flat table
- Custom Order in WP Query
- Fetch posts from current week (Sunday to Saturday)
- If specific user role then sticky post
- Hide Post comments when displayed via WP_Query
- Search query – exact post title match
- Hiding posts in a list from specified categories
- Converting multiple loops into one single loop with pagination
- Display posts with comments closed, with pagination?
- Group posts by year in loop
- posts_per_page doesnt work
- WP_Query posts_per_page ignored
- wp query with dynamic taxonomies and terms?
- How would I get 1 latest post from a query for 5 posts?
- How to get posts by multiple post slugs? [duplicate]
- What Is meta_id In wp_postmeta?
- Blogroll – Different layout for first post
- How to get most recent commented post above new submitted post in WordPress?
- WP_Query do not load specifed number of post
- WP_Query: offset ignored when posts_per_page is -1?
- wp_query ‘s’ parameter does not work with custom post type
- How to start with post number x?
- WP Query related posts by current page Tag ID
- Exclude posts with empty post_content in wp_query
- Exclude posts from featuring
- I want to query posts in monthly basis
- Lazy Load using WP_Query pagination
- Only display a certain number of posts, dependent on how many posts there are available in a query
- How do I use `posts_distinct` correctly?
- AJAX filter posts by year
- How can I remove posts of a certain category from homepage after a specified time period?
- Automatic value for custom fields for posts
- Loop through all product posts?
- Custom WP_QUERY $args
- Improving WP_Query for performance when random posts are ordered
- Automatic post deletion
- Why won’t my taxonomy query show up?
- Should $found_posts be returned as string in ‘found_posts’ filter hook?
- Get random posts between specific dates / of specific age
- WP_Query get posts from custom posts by category
- Accessing post->ID outside of the loop for listing child pages
- How to find what index page a post is on?
- WP Query – duplicated posts once including tags in search results