-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
]); | ||
|
||
} ); |