“Your Name.” cast shows 2,404 pages of actors
Closed this issue · 4 comments
Visiting https://wpmovies.dev/movies/your-name-2/ under “Cast” shows 2,404 pages, which is a lot :-)
Installing locally, I couldn't reproduce the issue, as the database is different.
I suspect it has something to do with https://wpmovies.dev/movies/your-name/, which is a different-ish movie, but the slugs generated from a title are probably the same.
You're right! Thanks for noticing 🙂 We are relying on the slug to link the cast with the movies. Each movie is at the same time a post (of the Movies custom post type), and a taxonomy used by actors (of the Movies custom taxonomy). The same applies to actors the other way around.
I just deleted the second "Your Name" movie and changed the slug to ensure it matches. The issue should be solved now.
@SantosGuillamot is there a way for us to not rely on slugs? Or for this to be more resilient in general? The whole premise of the interactivity API is to use the power of the WP backend and many-to-many is a common relationship, so being able to represent it in a solid way is important both for the user and for the developer experience.
Just to ensure we are aligned, relying on the slugs is totally independent of the interactivity API. It's just the way we decided to manage the backend.
When we started it, this movies site was supposed to be an experimental demo example of the Interactivity API so, as long as the backend was working fine, we didn't worry too much about how it was implemented because that wasn't the purpose of the experiment/demo. Our idea was that users would only be interested in the code examples of interactive blocks: link, not how the backend is populated.
We know the slug isn't 100% reliable, but we assumed that risk because when it doesn't match it just shows a wrong query loop (which at least doesn't break the page), and we can always fix that manually for the edge cases.
Having said that, and forgetting about the interactivity API for the moment, let me explain how we are populating the backend with some content, to discuss if we can handle it in a better way:
First, it's important to mention that we tried to rely on existing core solutions and not using external plugins. From there, the plugin:
- Creates two new custom post types: Movies and Actors.
- Creates two new custom taxonomies: Movies and Actors. The Movies taxonomy is used in the Actors custom post type. And the Actors taxonomy is used in the Movies custom post type.
- With a corn, fetches the most popular movies from the TMDB, with some metadata.
For each movie
Let's use The Godfather as an example.
- Creates a new movie post named "The Godfather". Populating the metadata, images, videos...
- Adds the genres "Crime" and "Drama" as a common category.
- Creates a new movie taxonomy named "The Godfather".
- Gets the list of actors and iterate over them.
For each actor
Let's use Al Pacino as an example.
- Creates a new actor post named "Al Pacino". Populating the metadata, images, videos...
- Adds "The Godfather" tag we created as part of the "movies taxonomy" to the current actor "Al Pacino".
- Creates a new actor taxonomy named "Al Pacino".
- Adds the new "Al Pacino" tag as part of the "actors taxonomy" to the current movie "The Godfather".
From there, in the movies template (and the actors template), we created a variation of the Query Loop block that, using the slug of the current movie post, gets the actors of that movie taxonomy. The easiest way we found to make that connection was using the slug because we thought we couldn't rely on the ID, because that one might be different.
With everything in mind, I guess there are different ways to handle this but, as this was expected to be a demo to showcase how the Interactivity API is used and share some code examples of that, we didn't care that much about how the database was populated as long as it is working.
I'm happy to hear other alternatives and revisit how the backend is populated if we consider it relevant for the demo.
For more context, we wanted to create the "movies demo" app so we can submit it to Addy Osmani's list of frameworks at some point, and people can compare it with JS frameworks in terms of UX and performance: https://twitter.com/addyosmani/status/1582798642015924224
The JS frameworks are using the TMDB API as the backend, so to replicate that, we had to create a way to inject that data into WordPress.