I am attempting to simply pull in all projects in a specific category (e.g. ‘websites’ or ‘featured’).
When using:
$args = array(
'post_type' => 'project',
'category_name' => 'websites',
'posts_per_page' => 10,
);
Nothing is returned.
When using simply:
$args = array(
'post_type' => 'project',
);
I do actually get posts (projects) returning, just not in the category I want.
Here is my full code:
function gmb_register_project_section () {
$args = array(
'post_type' => 'project',
'category_name' => 'websites',
'posts_per_page' => 10,
);
$post_query = new WP_Query($args);
if ($post_query->have_posts()) :
$output = '<div class="gmb_custom-project-module">';
while ($post_query->have_posts()) {
$post_query->the_post();
$output .= '<a href="'. get_permalink(). '"><article class="gmb_project-item" style="background: url(''. get_the_post_thumbnail_url(). '') no-repeat center center;"><div class="inner"><h2>'.
get_the_title(). '</h2></div></article></a>';
}
wp_reset_postdata();
$output .= '</div>';
endif;
return $output; }
add_shortcode('gmb_project_section', 'gmb_register_project_section');
I am using the Divi theme, with a code module which allows you to input short codes into.
Thanks in advance,
Ben
2
Answers
Try this bro: