Вы смешиваете в некоторых ;
, где вам нужно ,
, потому что это массив значений, и вы добавили endif , когда вам это не нужно. Попробуйте это.
function addschema() //Function for Schema.org
{
global $post;
if (is_singular('post')) { //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(array(
'@type' => "SportsTeam",
'name' => "Team A",
'image' => get_post_meta( get_the_ID(), 'logo_left' )),
array('@type' => "SportsTeam",
'name' => "Team B",
'image' => get_post_meta( get_the_ID(), 'logo_left' ))
),
'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
}
}
Это должно сгенерировать JSON, как это. Хотя в моем сообщении не было части post_meta, чтобы заполнить некоторые части.
{
"@context": "http://schema.org",
"@type": "SportsEvent",
"name": "some stuff",
"description": "",
"url": "http://192.168.33.10/wordpress/blog/2019/11/28/some-stuff/",
"startDate": [],
"endDate": [],
"image": false,
"competitor": [
{
"@type": "SportsTeam",
"name": "Team A",
"image": []
},
{
"@type": "SportsTeam",
"name": "Team B",
"image": []
}
],
"location": {
"@type": "Place",
"name": [],
"address": {
"@type": "PostalAddress",
"postalCode": [],
"streetAddress": [],
"addressLocality": [],
"addressRegion": [],
"addressCountry": []
}
}
}