Problems with Wordpress Loop

Asked

Viewed 32 times

1

I’m creating the page Category.php and using a Custom Post Type called Father. Within that post type has some categories: 1, 2, 3, 4 etc. What I wanted was to enter the page category 4, showed only the posts of this category, but is showing all the posts that Post Type.

The loop that I’m using is this:

$args = array(
    'post_type' => 'pai',
); 

$loop = new WP_Query($args);
if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();

<p>Existe Posts</p>

endwhile;

else:

<p>Não Existe Posts...</p>

endif;
wp_reset_postdata();
  • So I don’t understand

  • Let me try to explain to you what I need, on each page of the categories ex: site.com/cat/2 I need you to show only the posts of this category and not all, which is what’s happening with this loop I showed you.

  • So, the answer I said worked... You put the category you want for example category 4 and there will be shown posts category 4

  • Yes, but on all pages will show posts of category 4.

  • Have you tried filtering the data on WP_Query https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters ?

  • It doesn’t work :( , Will I need to make a file category-1.php for each of the categories? I wanted to do everything in the file Category.php

  • If you will put only post for such category, da para você fazer relação entre elas

  • And how I do it?

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.