Title: get_posts with meta_query and include array
Last modified: January 22, 2026

---

# get_posts with meta_query and include array

 *  [nitrospectide](https://wordpress.org/support/users/nitrospectide/)
 * (@nitrospectide)
 * [4 months, 2 weeks ago](https://wordpress.org/support/topic/get_posts-not-working-with-include-array/)
 * The following query works, but I’m not sure how to modify it to accomplish what
   I want.
 *     ```wp-block-code
       $authorPosts = get_posts(array(  'post_type' => 'post',  'posts_per_page' => -1,  'meta_query' => array(    array(      'key' => 'author',      'value' => '"' . get_the_ID() . '"',      'compare' => 'LIKE'    )  )));
       ```
   
 * Now I want to manually include a few posts that do not have the author field 
   value that’s in the meta_query. How can I include them anyway? Where can I integrate
   the following?
 * `'include' => array( 9048, 6289 ),`
    -  This topic was modified 4 months, 2 weeks ago by [nitrospectide](https://wordpress.org/support/users/nitrospectide/).
    -  This topic was modified 4 months, 2 weeks ago by [nitrospectide](https://wordpress.org/support/users/nitrospectide/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [4 months, 2 weeks ago](https://wordpress.org/support/topic/get_posts-not-working-with-include-array/#post-18795490)
 * It should just be:
 *     ```wp-block-code
       $authorPosts = get_posts(    array(        'post_type' => 'post',        'posts_per_page' => -1,        include' => array( 9048, 6289 ),        'meta_query' => array(            array(                  'key' => 'author',                  'value' => '"' . get_the_ID() . '"',                  'compare' => 'LIKE'            )        )    ));
       ```
   
 * But…
 * While I haven’t looked into it, the ‘include’ definition may only include those
   two posts and not the others from the author. You’d have to check yourself.
 * If it doesn’t work the best thing to do is two separate calls and then combine
   the two post arrays into one. It’s a bit more custom work, but that might be 
   the way to get it sorted out.
 *  Thread Starter [nitrospectide](https://wordpress.org/support/users/nitrospectide/)
 * (@nitrospectide)
 * [4 months, 2 weeks ago](https://wordpress.org/support/topic/get_posts-not-working-with-include-array/#post-18796308)
 * What you present is what I initially tried, but it actually returned no posts.
   I thought that maybe it was because setting it up this way makes it look for 
   the intersection of these two things: a post that is one of those two listed,
   AND that matches the meta query. Maybe not, but it seemed to explain why no posts
   were returned.
 * If I go the other route, can I just merge the two arrays? Any tips on getting
   them interleaved as if they came out as the result of one query, rather than 
   the ‘include’ ones just being glommed on at the beginning or end?
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [4 months, 2 weeks ago](https://wordpress.org/support/topic/get_posts-not-working-with-include-array/#post-18796371)
 * Most parameters in WP_Query get logically ANDed, it’s likely what’s happening
   here. You want OR logic, but the only way to get that with WP_Query is to alter
   the actual SQL string via the “posts_request” filter. Query string manipulation
   is inherently weak IMO, but it is a possible solution.
 * Or you could compose your own SQL and not use WP_Query. Making two queries and
   merging is a reasonable solution as long as the queries aren’t taking too long
   to execute. But merging while maintaining sort order can become difficult if 
   the results are paginated. If not paginated, you could combine the results, then
   usort() the combined array. Another way would be to keep separate results arrays
   and alter the output loop to appropriately slip in results from the second array
   during output.
    .

Viewing 3 replies - 1 through 3 (of 3 total)

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fget_posts-not-working-with-include-array%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 3 replies
 * 3 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [4 months, 2 weeks ago](https://wordpress.org/support/topic/get_posts-not-working-with-include-array/#post-18796371)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
