Commit 2c715598 authored by Andrius Mickus's avatar Andrius Mickus

add seo description to Yoast meta desc

parent 80f2e007
...@@ -133,9 +133,33 @@ class JobsImporter ...@@ -133,9 +133,33 @@ class JobsImporter
} }
} }
foreach ($this->primaryTerms as $term => $termKey) { // Set primary properties
if (is_plugin_active('wordpress-seo/wp-seo.php')) {
update_post_meta($podId, "_yoast_wpseo_primary_{$term}", $termKey); foreach ($this->primaryTerms as $term => $termKey) {
update_post_meta($podId, "_yoast_wpseo_primary_{$term}", $termKey);
}
}
$this->addSeoProperties($ad, $podId);
}
}
/**
* Add SEO properties for ad
* @uses Yoast SEO plugin
*
* @param $ad
* @param $postId
*/
private function addSeoProperties($ad, $postId)
{
if (is_plugin_active('wordpress-seo/wp-seo.php')) {
foreach ($ad['seo_properties'] as $key => $item) {
update_post_meta($postId, '_yoast_wpseo_' . $key, $item);
} }
} }
} }
...@@ -390,4 +414,25 @@ class JobsImporter ...@@ -390,4 +414,25 @@ class JobsImporter
} }
private function add_to_yoast_seo($post_id, $metatitle, $metadesc, $metakeywords){
$ret = false;
// Include plugin library to check if Yoast Seo is presently active
include_once( ABSPATH.'panel/includes/plugin.php' );
if(is_plugin_active('wordpress-seo/wp-seo.php')) {
//plugin is activated
$updated_title = update_post_meta($post_id, '_yoast_wpseo_title', $metatitle);
$updated_desc = update_post_meta($post_id, '_yoast_wpseo_metadesc', $metadesc);
$updated_kw = update_post_meta($post_id, '_yoast_wpseo_metakeywords', $metakeywords);
if($updated_title && $updated_desc && $updated_kw){
$ret = true;
}
}
return $ret;
}
} }
...@@ -49,6 +49,10 @@ class JsonDataCollector ...@@ -49,6 +49,10 @@ class JsonDataCollector
], ],
]; ];
protected $seoProperties = [
'metadesc' => 'seo_description'
];
// Custom posts data map // Custom posts data map
protected $posts = [ protected $posts = [
'division' => [ 'division' => [
...@@ -130,6 +134,7 @@ class JsonDataCollector ...@@ -130,6 +134,7 @@ class JsonDataCollector
$item['terms'] = $this->getTerms($ad); $item['terms'] = $this->getTerms($ad);
$item['posts'] = $this->getPosts($ad); $item['posts'] = $this->getPosts($ad);
$item['relations'] = $this->relationsMap; $item['relations'] = $this->relationsMap;
$item['seo_properties'] = $this->getSeoProperties($ad);
$result[] = $item; $result[] = $item;
}; };
...@@ -151,6 +156,20 @@ class JsonDataCollector ...@@ -151,6 +156,20 @@ class JsonDataCollector
return $result; return $result;
} }
private function getSeoProperties($ad)
{
$result = [];
foreach ($this->seoProperties as $propertyKey => $propertyValue) {
if (isset($ad->{$propertyValue})) {
$dataValue = $ad->{$propertyValue};
}
$result[$propertyKey] = $this->getValue($dataValue);
}
return $result;
}
private function getTerms($ad) private function getTerms($ad)
{ {
$result = []; $result = [];
......
...@@ -72,7 +72,7 @@ function do_import() ...@@ -72,7 +72,7 @@ function do_import()
// pll_the_languages( array( 'dropdown' => 1 ) ); // pll_the_languages( array( 'dropdown' => 1 ) );
// exit(); // exit();
// } // }
print_r("Data source: $inputFile<br><br>"); print_r("Data source: $inputFile<br><br>");
// JSON reader // JSON reader
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment