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"=>"projec t_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"=>"projec t_post") );
while ( $the_query->have_posts() ) : $the_query->the_post();
$image = wp_get_attachment_image_sr c( get_post_thumbnail_id( $post->ID ), 'project_preview_big' );
$image = $image[0];
$categories = wp_get_post_terms($post->I D,"project s_category ");
$category = array();
if(count($categories)){
foreach($categories as $categ){
array_push($category,$cate g->name);
}
$category = implode(",",$category);
}
else{
$category = "";
}
$cats = array();
foreach($categories as $cat){
array_push($cats,$cat->ter m_id);
}
$cats = implode(",",$cats);
?>
I'm trying to modify the query bellow I tried to change the line $the_query = new WP_Query( array("post_type"=>"projec
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"=>"projec
while ( $the_query->have_posts() ) : $the_query->the_post();
$image = wp_get_attachment_image_sr
$image = $image[0];
$categories = wp_get_post_terms($post->I
$category = array();
if(count($categories)){
foreach($categories as $categ){
array_push($category,$cate
}
$category = implode(",",$category);
}
else{
$category = "";
}
$cats = array();
foreach($categories as $cat){
array_push($cats,$cat->ter
}
$cats = implode(",",$cats);
?>
the_query = new WP_Query( array("post_type"=>"projec t_post","c at"=>4) );
ASKER
It shows empty page e.g no posts are displayed also the filter button stops working.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.