Pytanie poniekad z wordpressa ale z natury czysto z PHP. Chodzi o to ze taki kod:

  1. $args_id_parent = array(
  2. 'post_type' => 'produkty',
  3. 'post_parent' => 0,
  4. 'posts_per_page'=>-1,
  5. 'post_status'=>'publish'
  6. );
  7. $query_id_parent=new WP_Query($args_id_parent);
  8. $where .= " AND (";
  9. while($query_id_parent->have_posts()):
  10. $query_id_parent -> the_post();
  11. $where .='post_parent = "'.get_the_ID().'" OR ';
  12. endwhile;
  13. $where=substr($where,0,-3);
  14.  
  15. $where .= ') AND (post_status="publish")';
  16. echo $where;

drukowany przez echo - pieknie generuje stringa ktory wyglada w moim przypadku tak:

  1. AND (post_parent = "63" OR post_parent = "62" OR post_parent = "60" OR post_parent = "59" OR post_parent = "58" OR post_parent = "57" OR post_parent = "56" OR post_parent = "55" ) AND (post_status="publish")

I tak wlasnie wklejony string dziala poprawnie.

Natomiast problem pojawia sie gdy probuje to podpiac do zmiennej i pozniej wykonac juz w wordpressie - wygalda to tak:

  1. add_filter('posts_where', 'add_post_parents', 1);
  2. function add_post_parents($where){
  3. $args_id_parent = array(
  4. 'post_type' => 'produkty',
  5. 'post_parent' => 0,
  6. 'posts_per_page'=>-1,
  7. 'post_status'=>'publish'
  8. );
  9. $query_id_parent=new WP_Query($args_id_parent);
  10. $where .= " AND (";
  11. while($query_id_parent->have_posts()):
  12. $query_id_parent -> the_post();
  13. $where .='post_parent = "'.get_the_ID().'" OR ';
  14. endwhile;
  15. $where=substr($where,0,-3);
  16.  
  17.  
  18. //$where= 'AND (post_parent = "63" OR post_parent = "62" OR post_parent = "60" OR post_parent = "59" OR post_parent = "58" OR post_parent = "57" OR post_parent = "56" OR post_parent = "55" ) AND (post_status="publish")';
  19. $where .= ') AND (post_status="publish")';
  20. return $where;
  21. }
To co jest zakomentowane to to efekt jaki powinien wydrukowac powyzszy kod, ale pojawia sie jakis blad chyba bo nie dostaje zadnego wyniku - nie dostaje odpowiedzi z bledami... zapewne sa tam wylaczone. Wracajac do setna co tam moge zle robic ze wordpress mi tego nie przyjmuje a to co zakomentowane elegancko dziala...