Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Filter widgets by certain sidebar doesn't work with GraphQL #7

@mwardew

Description

@mwardew

Hello.

I use Gatsby, Wordpress, plugin for gatsby gatsby-source-wordpress and this wp-api-menus-widgets-endpoints plugin.

My goal is to access widgets that belongs to certain sidebar - home_right_1.

Inside endpoint description it should work and it works.. but I can't create right GraphQL query - "Limit result set to widgets assigned to this sidebar."

Endpoint:

    "namespace": "wp/v2",
    "methods": [
        "GET",
        "POST"
    ],
    "endpoints": [
        {
            "methods": [
                "GET"
            ],
            "args": {
                "context": {
                "required": false,
                "default": "view",
                "description": "Scope under which the request is made; determines fields present in response.",
                "type": "string"
            },
            "page": {
                "required": false,
                "default": 1,
                "description": "Current page of the collection.",
                "type": "integer"
            },
            "per_page": {
                "required": false,
                "default": 10,
                "description": "Maximum number of items to be returned in result set.",
                "type": "integer"
            },
            "search": {
                "required": false,
                "description": "Limit results to those matching a string.",
                "type": "string"
            },
            "sidebar": {
                "required": false,
                "description": "Limit result set to widgets assigned to this sidebar.",
                "type": "string"
            }
        }
}

This works in browser - output is exactly what I need

wp-json/wp/v2/widgets?sidebar=home_right_1

However I have a problem with GraphQL query. I thought I can do something like this.

{
  allWordpressWpWidgets( filter: {
      sidebar: {
          eq: "home_right_1"
      }
  } ) {
    edges {
      node {
        title
      }
    }
  }
}

It doesn't work.. But if I want for example only sticky posts I can easily do that.

{
  allWordpressPost( filter: {
      sticky: {
          eq: true
      }
  } ) {
    edges {
      node {
        title
      }
    }
  }
}

Is possible to get only widgets that belongs to sidebar or not?

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions