How to Filter posts in Query Loop to same post category?

Hi All,

Is there a simple way to filter all posts in a query loop to be the same category as the page the viewer is currently viewing?

So if the post has been marked as “Web Development”, only show posts that are also in the “Web Development” category?

1 Like

Hey @jamieatstf

Just as an idea as I havent tried 1.3.7 beta yet - and not sure if possible and or if you have tried. But have you tried creating the query loop and then using the loop in the related post element? I believe the related post has the relationship query (again not sure if it is possible, but this would be something I would look at).

1 Like

Yea, I can’t seem to get the Taxonomy filter to work either.
A great deal of my projects is based around loops with taxonomy filter ':smiley:

1 Like

I’m not sure if that feature is built in or not but you should be able to use the query_vars filter to do this.


I’ve figured out that the most handy for me was this:

With custom PHP function:

function post_cat_ids() {
    return implode(',', wp_get_post_categories( get_the_ID(), array( 'fields' => 'ids' ) ));

Is there a simple way to do this now, one year later? Without putting in code?

Hi @Anze ,

You may use this to achieve the same result,


Yup does not work for me. I see this as critical for my application. I have no idea where to place the PHP. So I cannot test that, a nod on this would be helpful. Otherwise, the only workaround I can see is to create hundreds of ACF post types which would mess up my dashboard somewhat, although I have other issues with ACF. Another alternative is to use a URL /beauty_cat/health-club/

Use Child of: {archive_title} in the query loop. Then it grabs the archive title that the user is currently viewing and shows only posts in the category in the loop.