New WordPress WP Query using posts from certain categories

There are some errors in your code, you have to change: $the_query -> have_posts() to $the_query->have_posts() $the_query -> the_post() to $the_query->the_post() WP_Query array(…) to WP_Query(array(…)) ‘showposts=6’ to ‘posts_per_page’ => 6 Try this instead $the_query = new WP_Query( array( ‘category_name’ => ‘portfolio’, ‘posts_per_page’ => 6 ) ); while ($the_query->have_posts()) : $the_query->the_post(); the_post_thumbnail(); endwhile;

Remove last comma from this query

Looks like you’re trying to build up some JSON. Why not use what PHP already provides, which has the advantage of escaping characters too? global $post; $data = array(); if ($loop->have_posts()) { while ($loop->have_posts()) { $loop->the_post(); $thumb=wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘full’); $thumb2=wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘medium’); $url = rwmb_meta( ‘smb_katalozi’ ); $data[] = array ( ‘image’ => … Read more