Skip to content

Commit

Permalink
add base files
Browse files Browse the repository at this point in the history
  • Loading branch information
ashhitch committed Dec 6, 2019
1 parent e8c5604 commit 1e93fd3
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
Thumbs.db
wp-cli.local.yml
node_modules/
*.sql
*.tar.gz
*.zip
.idea*
14 changes: 14 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]"
}],
"require": {
"wp-graphql/wp-graphql": ">=0.3.8",
"yoast/wordpress-seo": ">=12.3"
}
}
67 changes: 67 additions & 0 deletions wp-graphql-homepage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Plugin Name: WPGraphql Homepage
* Plugin URI: http://github.com/ashhitch/wp-graphql-homepage
* Description: A WPGraphQL Extension that adds a root query to the GraphQL schema that returns the front page
* Author: Ash Hitchcock
* Author URI: https://www.ashleyhitchcock.com
* Text Domain: wp-graphql-homepage
* Domain Path: /languages
* Version: 1.0.0
*
* @package WP_Graphql_Homepage
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

add_action( 'graphql_register_types', function() {

register_graphql_field( 'RootQuery', 'homepage', [
'type' => '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;
},
]);

} );

0 comments on commit 1e93fd3

Please sign in to comment.