Giter Site home page Giter Site logo

krishaamer / wp-graphql-polylang Goto Github PK

View Code? Open in Web Editor NEW

This project forked from valu-digital/wp-graphql-polylang

1.0 1.0 0.0 366 KB

WPGraphQL Polylang Extension for WordPress

Home Page: https://packagist.org/packages/valu/wp-graphql-polylang

License: GNU General Public License v2.0

Shell 4.96% PHP 93.83% Dockerfile 1.21%

wp-graphql-polylang's Introduction

WPGraphQL Polylang Extension

Extend WPGraphQL schema with language data from the Polylang plugin.

Features

For posts and terms (custom ones too!)

  • Adds language and translations fields
  • Filter with a language where argument
  • Set the language on create and update mutations
  • Show all translations in the api by default
    • Polylang patches the WP Query to only list items with the current default language. This plugin reverts that for the GraphQL api
  • ACF Options Pages support

Root queries

  • defaultLanguage get the current default language
  • languages list all configured languages

Menu

  • Filter menu items by language

For details please refer to the generated docs in GraphiQL.

Example

Example showing all features

query PolylangExample {
    # Filter pages by language. If not set it defaults to ALL
    pages(where: { language: EN }) {
        nodes {
            title

            # Get language of each page
            language {
                code # Language code
                name # Human readable name of the language
            }

            # Get links to the translates versions of each page
            # This is an array of post objects
            translations {
                title
                link
                language {
                    code
                }
            }
        }
    }

    # Taxonomies such as tags can be filtered like post objects
    tags(where: { language: EN }) {
        nodes {
            name
            language {
                code
                name
            }
        }
    }

    # Get translated version of a given menu
    menuItems(where: { language: EN, location: FOOTER_MENU }) {
        nodes {
            url
        }
    }

    # Get the default language
    defaultLanguage {
        name
        code
    }

    # Get all configured languages
    languages {
        name
        code
    }

    # Get translations for ACF Options Pages.
    # See the section in the README.
    siteSettings(language: EN) {
        siteSettings {
            footerTitle
        }
    }
}

Requirements

  • PHP 7.2 or later
  • WPGraphQL 0.13.x or later
  • Polylang 2.6.5 or later
    • The free version is enough
    • If you get the PRO version the pro features such as translated slugs will work too

Installation

If you use composer you can install it from Packagist

composer require valu/wp-graphql-polylang

Otherwise you can clone it from Github to your plugins using the stable branch

cd wp-content/plugins
git clone --branch stable https://github.com/valu-digital/wp-graphql-polylang.git

ACF Options Pages

In addition to WPGraphQL and Polylang plugins you'll need these plugins too

You can install the free plugins using Composer. You'll need to have the WordPress Packagist repository enabled.

composer require wp-graphql/wp-graphql-acf wpackagist-plugin/acf-options-for-polylang

When registering the Options Page you must pass in show_in_graphql and graphql_field_name arguments.

acf_add_options_page([
    'page_title' => __('Site settings', 'theme'),
    'menu_title' => __('Site settings', 'theme'),
    'menu_slug' => 'site-settings',
    'capability' => 'manage_options',
    'redirect' => false,
    'show_in_graphql' => true,
    'graphql_field_name' => 'siteSettings'
]);

Slack

You can find us from the WPGraphQL Slack on the #polylang channel.

WPML

But I'm using WPML?!

There's rburgst/wp-graphql-wpml.

Or you might want to checkout migration docs

https://polylang.pro/how-to-switch-from-wpml-to-polylang/

Contributing

Checkout CONTRIBUTING.md

wp-graphql-polylang's People

Contributors

esamattis avatar jasonbahl avatar simptheshrimp2 avatar davidfaber avatar huesy avatar philjohnson avatar tpaananen79 avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.