Coder Social home page Coder Social logo

Comments (3)

maybellyne avatar maybellyne commented on June 8, 2024

https://wordpress.org/support/topic/structured-data-through-multiple-bound-callbacks-in-filter/

from wordpress-seo.

enricobattocchi avatar enricobattocchi commented on June 8, 2024

Hi @controvi, sorry for the delay in my response.

The schema pieces collected via the wpseo_schema_graph_pieces filter are then filtered by a filter_graph_pieces_to_generate method which ensures that there is a piece per identifier; if the identifier is not explicitly set, it's created from the class name, as you can see here.
In your snippet I suppose that the CustomGraphData objects don't have different identifiers, so they are in turn added to the ['customgraphdata'] key, with the second one overwriting the first and the third one overwriting the second:

		foreach ( $graph_pieces as $piece ) {
			$identifier = \strtolower( \str_replace( 'Yoast\WP\SEO\Generators\Schema\\', '', \get_class( $piece ) ) );
			if ( isset( $piece->identifier ) ) {
				$identifier = $piece->identifier;
			}

			/* ... */

			$pieces_to_generate[ $identifier ] = $piece;
		}

To fix that, you can either set different a different $identifier property value for each one of the objects, or use different classes.

I hope this helps!

from wordpress-seo.

controvi avatar controvi commented on June 8, 2024

Hey,
No worries about the late answer.
I found a workaround that seems to work just as well but just makes it 1 call to generated it all.

I do wanted to dive a little deeper into that if I may.
Reason for it is that I don't really understand why this is the way it works.
Whenever I load in a piece to the pieces array, there doesn't have to be a check of what does or doesn't have to be loaded.
As far as I tested, default wordpress behavior doesn't do this either.

Another thing that is weird is that when looking at the api documentation about this, it doesn't tell me to use an $identifier anywhere. Even when looking it up on google and searching for a week, I never found any reference to it. (Not saying I perfectly search the web thought. Can have overlooked something somewhere.)

Maybe it would be good to add something to the documentation about this.
I am trying to add custom graph data to the pieces array for multiple blocks but currently just concat the json through 1 class that eventually loads it all in at once.
Thought still dynamic it is more code than I would have wished.

Finally, just to be sure I understand the code.
I need to add a property "identifier" to the class object that is set in the pieces array.
That identifier will be used to keep all pieces separate and eventually loaded correctly, right?

Again thanks for the reply.
Hope that the docs can be updated as well for future reference.
If there is already mention of this in the docs somewhere I would love to have the link to it.
Especially for future reference when people have the same issue and reach this support ticket through the WordPress forums.

Regards

from wordpress-seo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.