Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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