![]() |
I am trying to splice together 2 post types and pull in 8 posts/events greater than the current day. I am struggling to get the default post type posts to show up though. Right now only the events are showing up - and I think it is something to do with my meta_query. The code is below:
Any help would be greatly appreciated. Solution - 1Hello the problem is that post dont have the meta. maybe adding one more condition to the meta query will help like this global $post; $today = date( 'Ymd' ); $args = array( 'post_type' => array('post', 'tribe_events'), 'post_status' => 'publish', 'posts_per_page' => 8, 'meta_query' => array( 'relation' => 'OR', 'event_date' => array( 'key' => '_EventStartDate', 'compare' => '>=', 'value' => $today, ), 'date' => array( 'key' => 'date', 'compare' => '>=', 'value' => $today, ), array( 'key' => '_EventStartDate', 'value' => '', 'compare' => 'NOT EXISTS', ) ), 'orderby' => array( 'event_date' => 'ASC', 'date' => 'ASC' ), ); but the best solution is have the 2 posts types have the same meta field name to compare Solution - 2Try this custom query: $list will contain id of posts in true order. Then use get_post() for each. Solution - 3Hi James, Here you are the code As this is WordPress SQL query, wordpress modify and results the answer equivalent to INNER JOIN. . Solution - 4hello, can you try using this code instead?
Solution - 5
try changing your post_type Solution - 6You are doing a meta_query using _EventStartDate but posts do not have that meta field so it will return negative for any of those. It isn't possible. You would have to add a new meta field for the posts to recognize in your OR part of the query. |
Wordpress |
Type: | Code Example |
Category: | Coding |
Sub Category: | Code Example |
Uploaded by: | Admin |
Views: | 13 |