Reputation: 13
I need to show some data with post_type
set to project
in my wordpress index.php, but despite setting post_type
to project
in my code, the default and usual wordpress posts with post_type: post
are shown.
I've searched for a solution for a couple hours, but I didn't find anything useful from stackoverflow or google search.
This is my code:
<?php
$args1=array(
'posts_per_page' => 3,
'offset' => 0,
'category' => '',
'category_name' => '',
'orderby' => 'post_date',
'order' => 'DESC',
'include' =>'',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'project',
'post_mime_type' => '',
'post_parent' => '',
'post_status' => 'publish',
'suppress_filters' =>true,
);
$query_mine=new wp_Query('$args1');
while ($query_mine->have_posts()) {
$query_mine->the_post();
?>
<a href="<?php the_permalink(); ?>" title="more">
<div class="item active">
<div class="col-xs-6 col-sm-4">
<img src="<?php the_post_thumbnail_url(); ?>" alt="" class="img-carousel">
</div>
</div>
</a>
<?php
} ?>
I expected posts to be of type project
, but it shows posts of type post
.
Upvotes: 1
Views: 43
Reputation: 11533
Looks like you have a typo: you are passing a string instead of your array to WP_Query()
. Remove the single quotes from $args1
when passing to WP_Query( $args1 )
.
<?php
$args1 = array(
'posts_per_page' => 3,
'post_type' => 'project',
);
$query_mine = new WP_Query( $args1 );
if ( $query_mine->have_posts()) : while ( $query_mine->have_posts() ) : $query_mine->the_post();
?>
<a href="<?php the_permalink(); ?>" title="more">
<div class="item active">
<div class="col-xs-6 col-sm-4">
<img src="<?php the_post_thumbnail_url(); ?>" alt="" class="img-carousel">
</div>
</div>
</a>
<?php endwhile; endif; ?>
Upvotes: 1