Skip to content

Instantly share code, notes, and snippets.

@koen12344
Last active March 3, 2022 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koen12344/d33ffe8f0b78df530f37312279653f65 to your computer and use it in GitHub Desktop.
Save koen12344/d33ffe8f0b78df530f37312279653f65 to your computer and use it in GitHub Desktop.
Motors WordPress plugin add car data to Post to Google My Business plugin
<?php
if(interface_exists('\PGMB\Placeholders\VariableInterface')){
class PGMB_Motors_Variables implements \PGMB\Placeholders\VariableInterface {
private $listing_id;
public function __construct($listing_id){
$this->listing_id = $listing_id;
}
/**
* @return array Variable => Replacement
*/
public function variables(){
$years = get_the_terms($this->listing_id, 'ca-year');
$year = is_array($years) ? $years[0]->name : '';
return [
'%motors_price%' => get_post_meta($this->listing_id, 'price', true),
'%motors_sale_price%' => get_post_meta($this->listing_id, 'sale_price', true),
'%motors_seller_notes%' => get_post_meta($this->listing_id, 'stm_seller_notes', true),
'%motors_car_year%' => $year
];
}
}
}
function pgmb_motors_variables($decorators, $parent_post_id, $location){
if('listings' !== get_post_type($parent_post_id) || !class_exists('PGMB_Motors_Variables')){
return $decorators;
}
$decorators[] = new PGMB_Motors_Variables($parent_post_id);
return $decorators;
}
add_filter('mbp_placeholder_decorators', 'pgmb_motors_variables', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment