0
votes

I am a plugin developer and I'm using the following function to query particular posts in wordpress in my plugin. The problem is that even when $this->params['num'] is set to something like 12, the query is only returning 6 posts. My Plugin can be found HERE. It is working fine for me and in most cases. But i have got 2 odd support queries from users that in their case it did not work. Is it because of an older wordpress version or because of some conflict with their theme? Here is one conflicting page (he uses WP 3.0.5)

private function lcp_set_categories(){
    if($this->params['name'] != '' && $this->params['id'] == '0'){
        $this->cgid = $this->get_category_id_by_name($this->params['name']);
    }else{
        $this->cgid = $this->params['id'];
    }

    $lcp_category = 'cat=' . $this->cgid;

    //Build the query for get_posts()
    $cgquery = 'cat=' . $this->cgid .
                            '&posts_per_page=' . $this->params['num'] .
                            '&orderby=' . $this->params['orderby'] .
                            '&order=' . $this->params['order'] .
                            '&exclude=' . $this->params['excludeposts'] .
                            '&tag=' . $this->params['tags'] .
                            '&offset=' . $this->params['offset'].
                            '&meta_key=' . $this->params['customfield'].
                            '&meta_value=' . $this->params['customfieldvalue'];

    $this->cgposts = get_posts($cgquery);

}
2
UPDATE: MODIFIED the code, still having problem with some themes, like AGGREGATE theme. I believe its conflicting with some other posts loop. now i am using $tmp_query = new WP_Query; From my understanding i thought that "query" function calls the get_posts function which does NOT use the global $wp_query object. so it should not conflict with the themes loop $this->cgposts = $tmp_query->query($cgquery); - ansh
You are right. If you are creating a new WP_Query object then it shouldn't conflict with other queries in your theme. Try debugging your plugin/theme with Xdebug to find your conflict. - Javier Constanzo

2 Answers

0
votes

I believe you are calling the function with the wrong parameters. Refer here http://shibashake.com/wordpress-theme/wordpress-query_posts-and-get_posts for a quick explanation, and refer to the Codex for an in-depth explanation.

0
votes

Today I encountered the same problem. After a little bit of searching, I finally found this solution:

query_posts("showposts=-1");

By adding the parameter which set show posts to -1, I managed to get all posts. Hope this is helpful.