Hook for Custom Fields
This topic contains 7 replies, has 3 voices, and was last updated by Stiofan O’Connor 8 years, 1 month ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
May 23, 2017 at 6:53 am #379627
Hello,
I have created some custom fields for hotel classification, price range etc.
Hotel classification for instance needs to be entered as a number ranging from 1 to 5 in the backend but shown as a number of stars in the front-end.
What is the right hook to add a filter or action to add some replace functionality in my php-file?
I have searched the Codex documentation but could not find the right hook.
Best, Markus
May 23, 2017 at 6:10 pm #379731Hi Markus,
I asked to the developers if there is a hook for this and how you can use it.
They’ll let us know asap.
Thanks
May 23, 2017 at 7:04 pm #379744Hi Markus,
The hook name depends on the type of field used for the number and the HTML variable name used to name the custom field. If you provide wp-admin i will make you one example.
Thanks,
Stiofan
May 26, 2017 at 10:59 pm #380267Hi Stiofan,
Thank you for looking into that topic.
One good example for a custom field is geodir_classification in wp_geodir_gd_place_detail. The values need to be entered as number ranging from 1 to 5 but need to be shown as a number of stars in the front-end e.g. ***** for a 5-star hotel.
I would like to implement something like:
add_filter(‘XXX_HOOK’,’ggp_geodir_classification’);
function ggp_geodir_classification( $classification ){
if($classification ==’5′)
$stars = str_replace(‘5′,'<i class=”fa fa-star”></i><i class=”fa fa-star”></i><i class=”fa fa-star”></i><i class=”fa fa-star”></i><i class=”fa fa-star”></i>’,$classification);
elseif($classification ==’4′)
$stars = str_replace(‘4′,'<i class=”fa fa-star”></i><i class=”fa fa-star”></i><i class=”fa fa-star”></i><i class=”fa fa-star”></i>’,$classification);
elseif($classification ==’3′)
$stars = str_replace(‘3′,'<i class=”fa fa-star”></i><i class=”fa fa-star”></i><i class=”fa fa-star”></i>’,$classification);
elseif($classification ==’2′)
$stars = str_replace(‘2′,'<i class=”fa fa-star”></i><i class=”fa fa-star”>’,$classification);
else
$stars = str_replace(‘1′,'<i class=”fa fa-star”></i>’,$classification);
return $stars;
}What would be the XXX_HOOK?
Admin credentials follow as a private reply.
Best, Markus
May 26, 2017 at 11:00 pm #380268This reply has been marked as private.May 27, 2017 at 11:26 am #380302Thanks for the info i have added the following snippet to your site under “Code Snippets”
add_filter('geodir_custom_field_output_text','ggp_geodir_classification',15,3); function ggp_geodir_classification( $html,$location,$cf){ global $post; if($cf['name']!='geodir_classification'){return $html;} // if not the field we want then return standard $classification = $post->{$cf['htmlvar_name']}; if($classification =='5') $html = str_replace('5','<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i>',$html); elseif($classification =='4') $html = str_replace('4','<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i>',$html); elseif($classification =='3') $html = str_replace('3','<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i>',$html); elseif($classification =='2') $html = str_replace('2','<i class="fa fa-star"></i><i class="fa fa-star">',$html); else $html = str_replace('1','<i class="fa fa-star"></i>',$html); return $html; }
Thanks,
Stiofan
May 28, 2017 at 1:27 pm #380473Hi Stiofan,
thank you a lot! It works very well.
Best, Markus
May 29, 2017 at 10:20 am #380576You are welcome 🙂
Feel free to leave us a review to help us grow https://wordpress.org/support/plugin/geodirectory/reviews/?rate=5#new-post
Thanks,
Stiofan
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket