Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
use category names to append in post title
Browse files Browse the repository at this point in the history
  • Loading branch information
KhadijaMahanga committed Jan 15, 2020
1 parent 142d36f commit c648803
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions wp-content/themes/hurumap/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,17 @@ function post_object_field_query($args, $field, $post_id)
// filter for every field
add_filter('acf/fields/post_object/query', 'post_object_field_query', 10, 3);
/**
* Preppend Geography Name on topic pages and profile pages
* Preppend Category Name on topic pages and profile pages
* Topic and Section titles often repeat for geographies
* Assists in selection
*/
function post_object_field_result($title, $post, $field, $post_id)
{
$geography_list = (object) [
'burkina-faso' => 'Burkina Faso',
'democratic-republic-congo' => 'DR Congo',
'ethiopia' => 'Ethiopia',
'kenya' => 'Kenya',
'nigeria' => 'Nigeria',
'senegal' => 'Senegal',
'south-africa' => 'South Africa',
'tanzania' => 'Tanzania',
'uganda' => 'Uganda',
'zambia' => 'Zambia'
];
//get geography of the post
$geography_slug = get_field('geography', $post->ID);
$geography = $geography_list->$geography_slug;
// append post geography to each post result
$title = $geography . ' : ' . $title;
//get category of the post
$category_name = get_the_category($post->ID)[0]->name ;

// append post category country to each post result
$title = $category_name . ' : ' . $title;
return $title;
}
add_filter('acf/fields/post_object/result', 'post_object_field_result', 10, 4);
Expand Down

0 comments on commit c648803

Please sign in to comment.