-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Client Multisite example #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or 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
…need to set variables after the DB is imported to prevent it borking for multisite.
…gs so they could be re-used on the homepage.
… comment form and comment list.
package.json improvements suggested by Claude
ahuseyn
reviewed
Apr 4, 2025
Member
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@colinmurphy Looks nice 🚀 Tested it, builds and works well! Suggested couple typo fixes.
Co-authored-by: Huseyn Aghayev <[email protected]>
Co-authored-by: Huseyn Aghayev <[email protected]>
Member
Author
|
Thanks @ahuseyn Thanks for spotting those typos. Ready to be reviewed again @wpengine/headless-open-source |
ahuseyn
approved these changes
Apr 4, 2025
theodesp
approved these changes
Apr 7, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Example: Multisite Next.js App Router using the Fetch API
Table of Contents
Overview
An example mulitsite headless WordPress application using Next.js App Router and the fetch API to fetch data from WordPress using WPGraphQL It showcases different data fetching strategies, state management techniques, and modern web development patterns in a real-world application context. This also contains a full example using wp-env and sample data.
Prerequisites
Project Structure
Features
Covers various rendering patterns of Next.js
Multisite Features
Dynamic site management in next.config.mjs
Fetch data based off site key defined in next.config.mjs
Homepage dynamically fetches and displays data from multiple WordPress sites in the multisite network.
Catch-All Template
Blog features
Other Template Features
Screenshots
Running the example with wp-env
Prerequisites
Note Please make sure you have all prerequisites installed as mentioned above and Docker running (
docker ps)Setup Repository and Packages
git clone https://github.com/wpengine/hwptoolkit.gitexamples/next/client-multisite-app-router-fetch-data/example-appwithe.g.
Important
The site configuration is based off values set in example-app/next.config.mjs
If you want to add more sites please feel free to add more sites to your .env file and update the configuration in the next.config.mjs
Build and start the application
cd examples/next/client-multisite-app-router-fetch-datapnpm example:buildwill build and start your application.)wp-env/uploads.ziptowp-env/uploadswhich is mapped to the wp-content/uploads directory for the Docker container.example-appCongratulations, WordPress should now be fully set up.
The login details for the admin is username "admin" and password "password"
Important
There are issues with setting variables for multisite in .wp-env.json before converting the site to multisite. For this reason we set the variables after the sample database (which is multisite) is imported.
You also need to update the port in wp:multisite:set:variables if you ever change 8888
Command Reference
example:buildexample:devexample:dev:installexample:startexample:stopexample:prunewp:startwp:stopwp:multisite:set:variableswp-config.php.wp:destroywp:db:querywp:db:exportwp-env/db/database.sql.wp:db:importwp-env/db/database.sql.wp:images:unzipwp:images:zipDatabase access
If you need database access add the following to your wp-env
"phpmyadminPort": 11111,(where port 11111 is not allocated).You can check if a port is free by running
lsof -i :11111Adding more sites to the multisite examples
If you want to add more sites you need to do the followint
NEXT_PUBLIC_SPORT_WORDPRESS_URL=http://localhost:8888/sportYou then use the site key e.g.
sport_sitewhen fetching data with a template or thefetchGraphQLfunctione.g.
Note
Related issue
Closes #60