php - Wordpress my query post doesn't display my post with category
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 :
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>
So here is what you would need to do to display the post on the single page. You seem to have missed the
have_postso it needs to be like below
Note: This would go inside
You try using this loop with the
cat_idthat you have for the category you create.
You can have a try of the replaced code as follows.
You have missed the loops format.