Skip to content

Instantly share code, notes, and snippets.

View hereisfahad's full-sized avatar
🎯
Focusing

Fahad Jabbar hereisfahad

🎯
Focusing
View GitHub Profile
@jasonbahl
jasonbahl / like-posts.php
Created December 10, 2018 22:06
Adding a "likePost" mutation for WPGraphQL
add_action( 'graphql_register_types', function() {
register_graphql_field( 'Post', 'likeCount', [
'type' => 'Int',
'description' => __( 'The number of likes for the post', 'your-textdomain' ),
'resolve' => function( $post ) {
$likes = get_post_meta( $post->ID, 'likes', true );
return isset( $likes ) ? (int) $likes : 0;
}
] );