Title: PHP warnings when using CRP_Query
Last modified: December 23, 2023

---

# PHP warnings when using CRP_Query

 *  Resolved [lastnoob](https://wordpress.org/support/users/lastnoob/)
 * (@lastnoob)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/php-warnings-when-using-crp_query/)
 * Thanks for the great plugin!
   I use CRP_Query in one of my templates. It sometimes
   works, but sometimes throws a bunch of PHP warnings. Any idea what am I doing
   wrong?
 * Here’s the code:
 *     ```wp-block-code
       if(class_exists('CRP_Query')) :
           $args = array(
               'posts_per_page' => 6,
               'ignore_sticky_posts' => true,
               'no_found_rows' => true
           );
           // The Query.
           $recommended_posts = new CRP_Query( $args );
           if($recommended_posts->have_posts()) :
               while($recommended_posts->have_posts()) :
                   //do something
               endwhile;
           endif;
       endif;
       ```
   
 * And the warnings from Query Monitor:
 * > [View post on imgur.com](https://imgur.com/7u2GNf7)
 * I must be doing something wrong, would appreciate your advice on how to fix it.
   
   Thank you, appreciate your support!

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

 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/php-warnings-when-using-crp_query/#post-17311417)
 * The code looks fine to me and it only has an issue with a single post. I’m wondering
   if this is pulling some posts which are from an incorrect post type or incorrect
   ID.
 * You might want to pass a post_type like you’d do with WP_Query to limit to to
   specific ones.
 * Are you able to check which of these posts are giving an issue. Also in your 
   settings page, can you reset your settings as well.
 *  Thread Starter [lastnoob](https://wordpress.org/support/users/lastnoob/)
 * (@lastnoob)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/php-warnings-when-using-crp_query/#post-17312477)
 * Thanks for the reply! I really appreciate your help.
 * It only had an issue with a single post because it was the only post (for dev
   purposes). When introducing other posts, it throws an error for each.
 * > [View post on imgur.com](https://imgur.com/a/domuniV)
 * I’ve reset my settings and started passing a `post_type` in the arguments, but
   the issue persists. Is there anything I can do to debug this?
 *  Thread Starter [lastnoob](https://wordpress.org/support/users/lastnoob/)
 * (@lastnoob)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/php-warnings-when-using-crp_query/#post-17312925)
 * I was outside the loop, so the plugin couldn’t default and set the $source_post
   by getting the current post.
 * So I passed the `postid` in the argument (via `$wp_query->post->ID` ) and it 
   works now.
    -  This reply was modified 2 years, 5 months ago by [lastnoob](https://wordpress.org/support/users/lastnoob/).
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/php-warnings-when-using-crp_query/#post-17312967)
 * That’s great. Thank you for confirming. That’s a note I will make in my docs 
   as well as in most cases you would run it outside of the loop.

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

The topic ‘PHP warnings when using CRP_Query’ 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/)

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [php warnings](https://wordpress.org/support/topic-tag/php-warnings/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [warnings](https://wordpress.org/support/topic-tag/warnings/)

 * 4 replies
 * 2 participants
 * Last reply from: [Ajay](https://wordpress.org/support/users/ajay/)
 * Last activity: [2 years, 5 months ago](https://wordpress.org/support/topic/php-warnings-when-using-crp_query/#post-17312967)
 * Status: resolved