Create New Custom Field
This topic contains 11 replies, has 3 voices, and was last updated by Fernando 6 years ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support TicketTagged: mustisite calendar
-
AuthorPosts
-
February 19, 2019 at 5:09 pm #470069
Can you please confirm the following filter still works for GDV2 ?
add_filter(‘geodir_custom_fields_custom’,’geodir_custom_field_CUSTOMNAME’,10,2);
Thanks.
February 19, 2019 at 5:59 pm #470078Hi Fernando,
the filter is still there, not sure of the context though?
Let us know,
Thanks
February 19, 2019 at 7:35 pm #470087Okay.
I can create the following.
function custom_myobject($custom_fields,$post_type){
$custom_fields[‘myobject’] = array(
‘field_type’ => ‘text’,
‘class’ => ‘gd-myobject’,
‘icon’ => ‘fa fa-cog’,
‘name’ => __(‘myobject’, ‘geodirectory’),
‘description’ => __(‘Adds a input for myobject username.’, ‘geodirectory’),
‘defaults’ => array(
‘data_type’ => ‘VARCHAR’,
‘admin_title’ => ‘myobject’,
‘site_title’ => ‘myobject’,
‘admin_desc’ => ‘Enter myobject username’,
‘htmlvar_name’ => ‘myobjectusername’,
‘is_active’ => true,
‘for_admin_use’ => false,
‘default_value’ => ”,
‘show_in’ => ‘[detail]’,
‘is_required’ => false,
‘validation_pattern’ => ‘{1,3}’,
‘validation_msg’ => ‘Please enter number only.’,
‘required_msg’ => ”,
‘field_icon’ => ‘fa fa-myobject’,
‘css_class’ => ”,
‘cat_sort’ => false
));
return $custom_fields;
}
add_filter(‘geodir_custom_fields_custom’,’custom_myobject’,10,2);I need to insert a number ($number) as value.
After that I need to save it as a short code as [myobject obj_number=””]., the object number being the $number. This means I want the front end user to add just a number. But actually to be saved as a shortcode.
How would I write function (snippet) to achieve this.Thanks.
February 19, 2019 at 7:40 pm #470088I’ve flagged your request for the developers.
Thanks
February 19, 2019 at 8:28 pm #470090Thanks.
Pls note that I do not want to do the customization of $default_value in Line 1523 of class-geodir-settings-cpt-cf.php. But wish to achieve it by an external snippet function so that the custom function will not get affected by any future updates.
Rgds
February 20, 2019 at 4:39 am #470136Also, please note that my add filter will be..
add_filter(‘geodir_custom_fields’,’custom_myobject’,10,2);– Thanks
February 20, 2019 at 4:44 pm #470214Did u follow the instructions here? https://wpgeodirectory.com/custom-field-improvements-in-new-v1-6-6/
With v2 is pretty much the same except the field name prefix of “geodir_” is no longer needed so “geodir_twitter” would just be “twitter”.
If you need more help just let us know.
Thanks,
Stiofan
February 20, 2019 at 6:49 pm #470233Thanks for the reply.
Yes, I flowed the your instruction on GitHub as well.
I can make the custom field work.
I created a gd_calendar.But the calendar is unique for a gd_place.
I need to add a Shortcode something similar to “[mycal id=”1″] if I use the calendar id1.
Then, if I use calendar id-2 to a different post the shortcode would be [mycal id=”2”] etc.So, all I need the user to insert is the ID number only.
Not the whole Shortcode.How would I create a filter to achieve this.
So that I could allow user to inser ID numbers of different different calendars.Front end user will not see the shortcode.
Only inserting the number.– Thanks
February 21, 2019 at 4:14 am #470268I think I am getting there very slowly.
Can you please tell me how would I use a function similar to the following inside a Custom Field (for GD Sidebar).
QUOTE:
public function insert_shortcode_function(){
ob_start();
?>
function sd_insert_shortcode(){
$shortcode = jQuery(‘#sd-shortcode-output’).val();
if($shortcode){
jQuery(‘.gd-tab-settings-open textarea’).val($shortcode);
tb_remove();
}
}
<?php
return ob_get_clean();}
UNQUOTE:Then, I might be able to modify the function furthermore to get only number inserted, instead of the
[mycal id=”1″] as explained in my last post.– Thank you.
February 21, 2019 at 4:52 pm #470379OK, if u understand what you are trying to do then you can simply use a text input field, set it to number only and then that is all you need for the input, you don’t need to add a new field or worry about adding the shortcode on the fly with JS.
All you need to do is filter the output so insted of it outputting a number you make it output a shortcode or whatever…so the only code snippet you need to look at is this https://wpgeodirectory.com/custom-field-improvements-in-new-v1-6-6/#gist39301380
So for example if your field key was “mycal” you might have a code snippet like this:
function _my_mycal_output($html,$location,$cf){ global $post; $html = ''; // set it to empty first. if (isset($post->{$cf['htmlvar_name']}) && $post->{$cf['htmlvar_name']} != '' ){ $html .= do_shortcode("[mycal id=".$post->{$cf['htmlvar_name']}."]"); } return $html; } add_filter('geodir_custom_field_output_text_key_mycal','_my_mycal_output',10,3);
Thanks,
Stiofan
February 22, 2019 at 8:29 am #470538My requirement was wee bit complicated than I mentioned in the post.
However, your examples on the GitHub and guidance on this post helped me to arrive at the final solution and it works fine for me now.I shall later post a link of the working demo later.
Thank you very much once again.
Kind regards.
February 22, 2019 at 3:54 pm #470635Hi,
The working demo site with user customizable & iCal sync calendars is here at https://demo.rental.agency
Planning to install it on all subsites of our sub domain multisite rental advertising SaaS.
Rgds.
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket