Link to home
Start Free TrialLog in
Avatar of jakub99
jakub99

asked on

modifying WP Query

Hello,
I'm trying to modify the query bellow I tried to change the line $the_query = new WP_Query( array("post_type"=>"project_post") );

to  $the_query = new WP_Query( 'cat=4'  ); but it shows empty result on the page, my goal here is get all posts from specific category

original code:

<?php
                                                $the_query = new WP_Query( array("post_type"=>"project_post") );
                                                while ( $the_query->have_posts() ) : $the_query->the_post();
                                                $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'project_preview_big' );
                                                $image = $image[0];
                                                $categories = wp_get_post_terms($post->ID,"projects_category");
                                                $category = array();
                                                if(count($categories)){
                                                      foreach($categories as $categ){
                                                            array_push($category,$categ->name);
                                                      }
                                                      $category = implode(",",$category);
                                                }
                                                else{
                                                      $category = "";
                                                }
                                                $cats = array();
                                                foreach($categories as $cat){
                                                      array_push($cats,$cat->term_id);
                                                }
                                                $cats = implode(",",$cats);
                                                ?>
Avatar of john_yourspace
john_yourspace

the_query = new WP_Query( array("post_type"=>"project_post","cat"=>4) );
Avatar of jakub99

ASKER

It shows empty page e.g no posts are displayed also the filter button stops working.
ASKER CERTIFIED SOLUTION
Avatar of eemit
eemit
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial