PHP code example of wp-graphql / wp-graphql-acf
1. Go to this page and download the library: Download wp-graphql/wp-graphql-acf library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wp-graphql / wp-graphql-acf example snippets
function my_acf_add_local_field_groups() {
acf_add_local_field_group(array(
'key' => 'group_1',
'title' => 'My Group',
'show_in_graphql' => true,
'graphql_field_name' => 'myGroup',
'fields' => array (
array (
'key' => 'field_1',
'label' => 'Sub Title',
'name' => 'sub_title',
'type' => 'text',
)
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
),
),
));
}
add_action('acf/init', 'my_acf_add_local_field_groups');
function register_acf_options_pages() {
// check function exists
if ( ! function_exists( 'acf_add_options_page' ) ) {
return;
}
// register options page
$my_options_page = acf_add_options_page(
array(
'page_title' => __( 'My Options Page' ),
'menu_title' => __( 'My Options Page' ),
'menu_slug' => 'my-options-page',
'capability' => 'edit_posts',
'show_in_graphql' => true,
)
);
}
add_action( 'acf/init', 'register_acf_options_pages' )
Example Query
query GetMyOptionsPage {
myOptionsPage {
someCustomField
}
}