From 1e93fd31652e3212425a85ce2a8bd55006e61b75 Mon Sep 17 00:00:00 2001 From: Ash Hitchcock Date: Fri, 6 Dec 2019 20:47:04 +0000 Subject: [PATCH] add base files --- .gitignore | 8 +++++ composer.json | 14 +++++++++ wp-graphql-homepage.php | 67 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100755 .gitignore create mode 100644 composer.json create mode 100644 wp-graphql-homepage.php diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..71c72fe --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +Thumbs.db +wp-cli.local.yml +node_modules/ +*.sql +*.tar.gz +*.zip +.idea* \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..5aaeb71 --- /dev/null +++ b/composer.json @@ -0,0 +1,14 @@ +{ + "name": "ashhitch/wp-graphql-yoast-seo", + "description": "Query Yoast SEO data with wp-graphql", + "type": "wordpress-plugin", + "license": "GPL-3.0-or-later", + "authors": [{ + "name": "Ash Hitchcock", + "email": "hello@ashleyhitchcock.co.uk" + }], + "require": { + "wp-graphql/wp-graphql": ">=0.3.8", + "yoast/wordpress-seo": ">=12.3" + } +} \ No newline at end of file diff --git a/wp-graphql-homepage.php b/wp-graphql-homepage.php new file mode 100644 index 0000000..b419f91 --- /dev/null +++ b/wp-graphql-homepage.php @@ -0,0 +1,67 @@ + 'Page', + 'description' => __( 'Returns the homepage', 'wp-graphql-homepage' ), + 'resolve' => function() { + $page_on_front = get_option( 'page_on_front', 0 ); + + if ($page_on_front == 0 ) { + return null; + } + + query_posts(array( + 'p' => $page_on_front, + 'post_type' => 'page' + )); + the_post(); + + $homepage = $post; + wp_reset_query(); + + return $homepage; + }, + ]); + + register_graphql_field( 'RootQuery', 'pageForPosts', [ + 'type' => 'Page', + 'description' => __( 'Returns the page for posts', 'wp-graphql-homepage' ), + 'resolve' => function() { + $page_for_posts = get_option( 'page_for_posts', 0 ); + + if ($page_for_posts == 0 ) { + return null; + } + + + query_posts(array( + 'p' => $page_for_posts, + 'post_type' => 'page' + )); + the_post(); + + $postPage = $post; + wp_reset_query(); + + return $postPage; + }, + ]); + +} ); \ No newline at end of file