Skip to content

Commit

Permalink
WPNUX-10 support custom WP post types
Browse files Browse the repository at this point in the history
  • Loading branch information
vernaillen committed Jan 16, 2024
1 parent dba766e commit 88113e2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
39 changes: 39 additions & 0 deletions docs/content/2.advanced/1.custom-post-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: Custom Post Types
description:
---

## Create CPT in WordPress

https://developer.wordpress.org/reference/functions/register_post_type/
https://faustjs.org/guide/setting-up-custom-post-types-cpts-in-faust

## Check query in GarphiQl IDE

##

Create [movies].wql and put it in /queries folder in your project

```
fragment Movie on Movie {
...ContentNode
...NodeWithFeaturedImage
content
title
editorBlocks {
name
}
}
query Movies($limit: Int = 10) {
movies(first: $limit) {
nodes {
...Movie
}
}
}
```


```
const { data } = await useGraphqlQuery('Movies')
```
16 changes: 13 additions & 3 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ export default defineNuxtModule<ModuleOptions>({
cacheTagInvalidationDelay: 60000
}
})

const userQueryPath = '~/queries/'
.replace(/^(~~|@@)/, nuxt.options.rootDir)
.replace(/^(~|@)/, nuxt.options.srcDir)
logger.debug('Checking user query path:', userQueryPath)
const userQueryPathExists = existsSync(userQueryPath)
logger.debug('User query path exists:', userQueryPathExists)
const queryPaths = userQueryPathExists
? [ resolver.resolve(userQueryPath + '**/*.gql'), resolver.resolve('./runtime/queries/**/*.gql')]
: [ resolver.resolve('./runtime/queries/**/*.gql')]
logger.debug('Loading query paths:', queryPaths)

await installModule('nuxt-graphql-middleware', {
debug: true,
graphqlEndpoint: `${options.wordpressUrl}/graphql`,
Expand Down Expand Up @@ -153,9 +165,7 @@ export default defineNuxtModule<ModuleOptions>({
},
},
outputDocuments: true,
autoImportPatterns: [
resolver.resolve('./runtime/queries/**/*.gql'),
],
autoImportPatterns: queryPaths
})
const resolvedMCPath = resolver.resolve('./runtime/app/multiCache.serverOptions')
const templateMC = addTemplate({
Expand Down
2 changes: 1 addition & 1 deletion wpnuxt-wp-hook/wpnuxt-wp-hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @version 0.0.1
*/
/*
Plugin Name: WPNuxt Hooks
Plugin Name: WPNuxt: Hooks
Plugin URI: https://wpnuxt.com
Description: WordPress hooks for WPNuxt. Invalidate Nuxt cache on post update. Depends on the Faust.js™ plugin.
Author: Wouter Vernaillen
Expand Down

0 comments on commit 88113e2

Please sign in to comment.