• Resolved lastnoob

    (@lastnoob)


    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:

    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

    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

    (@ajay)

    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

    (@lastnoob)

    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

    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

    (@lastnoob)

    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 9 months, 3 weeks ago by lastnoob.
    Plugin Author Ajay

    (@ajay)

    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.