WordPress / wp-movies-demo

Demo of the Interactivity API
https://wpmovies.dev
GNU General Public License v2.0
195 stars 42 forks source link

“Your Name.” cast shows 2,404 pages of actors #59

Closed nb closed 10 months ago

nb commented 11 months ago

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.

SantosGuillamot commented 10 months ago

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.

nb commented 10 months ago

@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.

SantosGuillamot commented 10 months ago

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:

For each movie Let's use The Godfather as an example.

For each actor Let's use Al Pacino as an example.

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.

luisherranz commented 10 months ago

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.