Title: meta_query not working
Last modified: August 16, 2023

---

# meta_query not working

 *  Resolved [setick](https://wordpress.org/support/users/setick/)
 * (@setick)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/meta_query-not-working-2/)
 * Hi,
 * I try to query all posts that have value for a custom filed.
 * Let’s say I have a custom field named ‘Bookname’ and I want to get all posts 
   that have bookname values.
 * Here is the code:
 *     ```wp-block-code
       $args = array(
       'post_type' => 'post',
       'meta_query' => [
       [
       'key' => 'Bookname',
       ],
       ],
       'posts_per_page' => 5,
       );
   
       $posts = get_crp_posts($args); // show all posts
   
       $posts = get_posts($args); // Works as intended
       ```
   
 * CRP shows all posts whether the post has the custom field or not. However, the
   WP get_posts() works just fine.
 * I’ve tried for hours but cannot find out why so I come here for help, thanks.
    -  This topic was modified 2 years, 10 months ago by [setick](https://wordpress.org/support/users/setick/).

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

 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/meta_query-not-working-2/#post-16981350)
 * I can confirm this bug. It should be fixed in the new version I’ve just pushed
   through. Please can you check and confirm?
 *  Thread Starter [setick](https://wordpress.org/support/users/setick/)
 * (@setick)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/meta_query-not-working-2/#post-16982034)
 * It works, thanks for saving my day!
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/meta_query-not-working-2/#post-16982262)
 *  Thanks for confirming!

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

The topic ‘meta_query not working’ is closed to new replies.

 * ![](https://ps.w.org/contextual-related-posts/assets/icon-256x256.png?rev=2985705)
 * [Contextual Related Posts](https://wordpress.org/plugins/contextual-related-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contextual-related-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contextual-related-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/contextual-related-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contextual-related-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contextual-related-posts/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Ajay](https://wordpress.org/support/users/ajay/)
 * Last activity: [2 years, 9 months ago](https://wordpress.org/support/topic/meta_query-not-working-2/#post-16982262)
 * Status: resolved