'post_type' => 'produkty', 'post_parent' => 0, 'posts_per_page'=>-1, 'post_status'=>'publish' ); $query_id_parent=new WP_Query($args_id_parent); $where .= " AND ("; while($query_id_parent->have_posts()): $query_id_parent -> the_post(); $where .='post_parent = "'.get_the_ID().'" OR '; endwhile; $where .= ') AND (post_status="publish")';
drukowany przez echo - pieknie generuje stringa ktory wyglada w moim przypadku tak:
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:
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...
add_filter('posts_where', 'add_post_parents', 1); function add_post_parents($where){ 'post_type' => 'produkty', 'post_parent' => 0, 'posts_per_page'=>-1, 'post_status'=>'publish' ); $query_id_parent=new WP_Query($args_id_parent); $where .= " AND ("; while($query_id_parent->have_posts()): $query_id_parent -> the_post(); $where .='post_parent = "'.get_the_ID().'" OR '; endwhile; //$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")'; $where .= ') AND (post_status="publish")'; return $where; }