У меня проблемы с правильной настройкой схемы с PHP для этого указанного c свойства - конкурент. Проблема в том, что вместо того, чтобы показывать двух конкурентов, инструмент тестирования разметки показывает только одного конкурента. Вот как выглядит мой код:
<?php
/**
* Plugin Name: Schema.org for Football
* Description: Add SportsEvent Schema.org in JSONld to site
* Plugin URI:
* Author: Danstan
* Author URI:
* Version: 1.0.0
* License: GPL2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
function addschema() //Function for Schema.org
{
global $post;
if (is_singular('h2h')) { //only for post type matches
$schema_sportsevent = array(
'@context' => "http://schema.org",
'@type' => "SportsEvent",
'name' => get_the_title($post->ID),
'description' => get_the_content($post->ID),
'url' => get_permalink(),
'startDate' => get_post_meta( get_the_ID(), 'start_date' ),
'endDate'=> get_post_meta( get_the_ID(), 'end_date' ),
'image' => get_the_post_thumbnail_url($post->ID),
'competitor' => array(
'@type' => "SportsTeam",
'name' => get_post_meta( get_the_ID(), 'home_team' ),
'image' => get_post_meta( get_the_ID(), 'logo_left' ),
),
'competitor' => array(
'@type' => "SportsTeam",
'name' => get_post_meta( get_the_ID(), 'away_team' ),
'image' => get_post_meta( get_the_ID(), 'logo_right' ),
),
'location' => array(
'@type' => "Place",
'name' => get_post_meta( get_the_ID(), 'venue_name' ),
'address' => array(
'@type' => "PostalAddress",
'postalCode' => get_post_meta( get_the_ID(), 'zip_postal_code' ),
'streetAddress' => get_post_meta( get_the_ID(), 'street_address' ),
'addressLocality' => get_post_meta( get_the_ID(), 'locality_city' ),
'addressRegion' => get_post_meta( get_the_ID(), 'address_region' ),
'addressCountry' => get_post_meta( get_the_ID(), 'country' ),
)
)
);
echo '<script type="application/ld+json">' . json_encode($schema_sportsevent) . '</script>';
//encode schema for matches
}
}
add_action('wp_head', 'addschema'); //Add Schema to header`