0

I have a strange situation, i'm working on wordpress website and creating a export plugin. On one page i have products name with checkbox and once i select few and submit it pass the value to next page. here is the code to get the value of checkboxes.

FIRST SCENARIO:

    if(isset($_POST['products_id'])) {
     $product= $_POST['products_id'];
     $allProducts= implode(",",$product);
     } 

 $sql = "SELECT DISTINCT {$fields} FROM {$this->db->posts} WHERE post_status in ('publish','future','private','draft', 'pending') {$post_type_filter} {$post_id_filter} {$post_status_filter} AND ID IN ($allProducts)  ORDER BY post_modified DESC";
        var_dump($sql);  
        return $sql;

HERE RESULT COMES AS: string(235) "SELECT DISTINCT ID,post_modified FROM wp_posts WHERE post_status in ('publish','future','private','draft', 'pending') AND post_type = 'products' AND post_status = 'publish' AND ID IN (1402,895,2801,2999,425) ORDER BY post_modified DESC"

SECOND SCENARIO: Here i'm not getting value from $_POST but directly giving to variable.

 $allProducts= "1402,895,2801,2999,425";

 $sql = "SELECT DISTINCT {$fields} FROM {$this->db->posts} WHERE post_status in ('publish','future','private','draft', 'pending') {$post_type_filter} {$post_id_filter} {$post_status_filter} AND ID IN ($allProducts)  ORDER BY post_modified DESC";
        var_dump($sql);  
        return $sql;

RESULT COMES AS: string(235) "SELECT DISTINCT ID,post_modified FROM wp_posts WHERE post_status in ('publish','future','private','draft', 'pending') AND post_type = 'products' AND post_status = 'publish' AND ID IN (1402,895,2801,2999,425) ORDER BY post_modified DESC"

in both case result is same as you see above. but when i run this it only work in 2nd scenario. Could any one suggest what is wrong in first scenario where i'm using POST method.???

  • "when i run this it only work in 2nd scenario" Which most likely means that the results are not the same, or that you do other things before sending the query. Either way it is not really a wordpress related question, more of a PHP debugging one. – Mark Kaplun Aug 9 '14 at 14:12
  • Thanks Mark for the reply, I'll take care for the appropriate area to post the question. But for above question i have used var_dump($sql); and it display the same result like i have posted. I have posted the exact query above which i've got once i run code. any other help? – Sameer Aug 9 '14 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.