php - Wordpress my query post doesn't display my post with category
520
I am new to wordpress, I have a post that has a category_name of offer and it has a content, here is the permalink :http://localhost/jcjohn/2016/09/20/what-we-offer/
Now I want to display the contents of my post from my section page.
Here is my code inside the section :
<section id = "offer">
<?php
$args = array(
'type' => 'post',
'posts_per_page' => 3,
'category_name' => 'offer',
);
$offerBlog = new WP_Query($args);
if ($offerBlog->have_post()):
while ($offerBlog->have_posts()):
$offerBlog->the_post();
get_template_part('content', get_post_format());
endwhile;
endif;
wp_reset_postdata();
?>
</section>
Answer
Solution:
So here is what you would need to do to display the post on the single page. You seem to have missed the
s
fromhave_post
so it needs to be like belowNote: This would go inside
index.php
Answer
Solution:
You try using this loop with the
cat_id
that you have for the category you create.You can have a try of the replaced code as follows.
You have missed the loops format.
Reference: