Function Reference: geodir_action_details_micordata
Summary
Output the posts microdata in the source code.
Description
This micordata is used by things like Google as a standard way of declaring things like telephone numbers etc.
Global Values
- $preview
- (bool) (required) True of on a preview page. False if not.
- Default: None
- $post
- (object) (required) The current post object.
- Default: None
Package
GeoDirectory
Parameters
- $post
- (object) (optional) The post object or blank.
- Default: None
Change Log
Since: 1.0.0
1.5.4 Changed to JSON-LD and added filters.
1.5.7 Added $post param.
Filters
‘geodir_details_schema’ [Line: 1437]
‘geodir_details_facebook_og’ [Line: 1453]
Source File
geodir_action_details_micordata() is located in geodirectory_template_actions.php [Line: 1313]
Source Code
function geodir_action_details_micordata($post='') { global $preview; if(empty($post)){global $post;} if ($preview || !geodir_is_page('detail')) { return; } // url $c_url = geodir_curPageURL(); // post reviews $post_reviews = get_comments(array('post_id' => $post->ID, 'status' => 'approve')); if (empty($post_reviews)) { $reviews = ''; } else { foreach ($post_reviews as $review) { if($rating_value = geodir_get_commentoverall($review->comment_ID)){ $reviews[] = array( "@type" => "Review", "author" => $review->comment_author, "datePublished" => $review->comment_date, "description" => $review->comment_content, "reviewRating" => array( "@type" => "Rating", "bestRating" => "5",// @todo this will need to be filtered for review manager if user changes the score. "ratingValue" => $rating_value, "worstRating" => "1" ) ); } } } // post images $post_images = geodir_get_images($post->ID, 'thumbnail', get_option('geodir_listing_no_img')); if (empty($post_images)) { $images = ''; } else { $i_arr = array(); foreach ($post_images as $img) { $i_arr[] = $img->src; } if (count($i_arr) == 1) { $images = $i_arr[0]; } else { $images = $i_arr; } } //print_r($post); // external links $external_links = array(); $external_links[] = $post->geodir_website; $external_links[] = $post->geodir_twitter; $external_links[] = $post->geodir_facebook; $external_links = array_filter($external_links); if(!empty($external_links)){ $external_links = array_values($external_links); } // reviews $comment_count = geodir_get_review_count_total($post->ID); $post_avgratings = geodir_get_post_rating($post->ID); // schema type $schema_type = 'LocalBusiness'; if(isset($post->default_category) && $post->default_category){ $cat_schema = geodir_get_tax_meta($post->default_category, 'ct_cat_schema', false, $post->post_type); if($cat_schema){$schema_type = $cat_schema;} if(!$cat_schema && $schema_type=='LocalBusiness' && $post->post_type=='gd_event'){$schema_type = 'Event';} } $schema = array(); $schema['@context'] = "https://schema.org"; $schema['@type'] = $schema_type; $schema['name'] = $post->post_title; $schema['description'] = wp_strip_all_tags( $post->post_content, true ); $schema['telephone'] = $post->geodir_contact; $schema['url'] = $c_url; $schema['sameAs'] = $external_links; $schema['image'] = $images; $schema['address'] = array( "@type" => "PostalAddress", "streetAddress" => $post->post_address, "addressLocality" => $post->post_city, "addressRegion" => $post->post_region, "addressCountry" => $post->post_country, "postalCode" => $post->post_zip ); if($post->post_latitude && $post->post_longitude) { $schema['geo'] = array( "@type" => "GeoCoordinates", "latitude" => $post->post_latitude, "longitude" => $post->post_longitude ); } if($post_avgratings) { $schema['aggregateRating'] = array( "@type" => "AggregateRating", "ratingValue" => $post_avgratings, "bestRating" => "5", // @todo this will need to be filtered for review manager if user changes the score. "worstRating" => "1", "ratingCount" => $comment_count ); } $schema['review'] = $reviews; /** * Allow the schema JSON-LD info to be filtered. * * @since 1.5.4 * @since 1.5.7 Added $post variable. * @param array $schema The array of schema data to be filtered. * @param object $post The post object. */ $schema = apply_filters('geodir_details_schema', $schema,$post); echo ''; $uploads = wp_upload_dir(); $facebook_og = (isset($post->featured_image) && $post->featured_image) ? '' : ''; /** * Show facebook open graph meta info * * @since 1.6.6 * @param string $facebook_og The open graph html to be filtered. * @param object $post The post object. */ echo apply_filters('geodir_details_facebook_og', $facebook_og,$post); }