[gatsby + wp + graphql] Query Help

Hey guys,

I really apologize if I posted this in the wrong place but I was wondering if anyone in here is just an expert at graphql queries and can help me with what I want to do.

Basically I have a news,reviews, and guides category and I want to pull all other associated categories within either the news, reviews, or guides.

Is there anyway to do this?

I would be shocked if any one could answer your question as is. Do you have code to show? What have you tried?

I do not think there is a way to dot his because my roommate has tried this for his coding project and he could not find out how to do this

Hey Eoja, I tried this. This gives me what I want but I can’t figure out how to query the slugs and names (only the databaseId).

allWpCategory(filter: {posts: {nodes: {elemMatch: {categories: {nodes: {elemMatch: {databaseId: {eq: 8}}}}}}}}) {

distinct(field: databaseId)

}

Hmm, I would imagine this is possible, I just have no idea where to start. Graphql looks pretty flexible

Yes, but as GraphQL is specific to the way your specific data is set up, and how it’s resolved on the back end (WP in this case). It’s a wee bit difficult to help without you providing some code and some indication of what you’ve tried. Like, eg something like (this is just a sketch written on my phone, it’s not code, don’t copy it):

query categoryPosts($cat) {
  QueryCategoryPosts($cat:cat) {
    posts: {
      edges: {
        nodes: {
          post: {
            id
            ...some other fields
           }
         }
       }
    }
    assocCats(cat: cat) {
      cats: {
        edges: {
          nodes: {
            cat: {
              id
              ...some other fields
            }
          }
        }
      }
  }
}

Except the queries would be split out to make it a bit easier to read. Or you load a small number of actual posts rather than just categories or whatever, thing is it’s difficult to know what without some hint as to what you’re currently doing

I knew it was possible! Thanks for leading me towards the right direction, Dan.