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:

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.

Hi,

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,

3 Likes