From c6488038640d32e51aa1ff92b723093b5ec1c2ea Mon Sep 17 00:00:00 2001 From: KhadijaMahanga Date: Wed, 15 Jan 2020 09:51:02 +0300 Subject: [PATCH] use category names to append in post title --- wp-content/themes/hurumap/functions.php | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/wp-content/themes/hurumap/functions.php b/wp-content/themes/hurumap/functions.php index a87a4be5..bda037e9 100644 --- a/wp-content/themes/hurumap/functions.php +++ b/wp-content/themes/hurumap/functions.php @@ -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);