Title: Filter request by meta_query value
Last modified: August 22, 2016

---

# Filter request by meta_query value

 *  Resolved [Kalagan](https://wordpress.org/support/users/kalagan/)
 * (@kalagan)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/filter-request-by-meta_query-value/)
 * Hi.
    I need to exclude some posts of the related posts results, depending of 
   meta value. I tryed this :
 *     ```
       function filter_crp_posts_where( $where, $id ) {
   
           global $wpdb;
           $where .= $wpdb->prepare(" AND $wpdb->posts.ID = $wpdb->postmeta.post_id");
           $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = 'post_parent_id'");
           $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_value < 1");
           return $where;
       }
       add_filter( 'crp_posts_where', 'filter_crp_posts_where', 10, 2 );
       ```
   
 * I want exclude posts with meta value “post_parent_id”>0 (all the “children” posts).
 * Is it possible ? Is it the good way ?
 * [https://wordpress.org/plugins/contextual-related-posts/](https://wordpress.org/plugins/contextual-related-posts/)

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

 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/filter-request-by-meta_query-value/#post-5849355)
 * Hi,
 * Have you seen the above working?
 * I believe you might also need to create a filter function for the crp_posts_join
   that will allow you to join the postmeta table to the original query.
 *  Thread Starter [Kalagan](https://wordpress.org/support/users/kalagan/)
 * (@kalagan)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/filter-request-by-meta_query-value/#post-5849426)
 * Hi Ajay.
 * My hook don’t work…
    Could you give me a example with the crp_posts_join filter?
 * Thanks you.
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/filter-request-by-meta_query-value/#post-5849427)
 * Hi,
 * You can check out my plugin which works as an addon to CRP
    [https://wordpress.org/plugins/crp-taxonomy/](https://wordpress.org/plugins/crp-taxonomy/)

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

The topic ‘Filter request by meta_query value’ 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: [11 years, 2 months ago](https://wordpress.org/support/topic/filter-request-by-meta_query-value/#post-5849427)
 * Status: resolved