Create New Custom Field

This topic contains 11 replies, has 3 voices, and was last updated by  Fernando 5 years, 2 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #470069

    Fernando
    Free User
    Post count: 120

    Can you please confirm the following filter still works for GDV2 ?

    add_filter(‘geodir_custom_fields_custom’,’geodir_custom_field_CUSTOMNAME’,10,2);

    Thanks.

    #470078

    Paolo
    Site Admin
    Post count: 31206

    Hi Fernando,

    the filter is still there, not sure of the context though?

    Let us know,

    Thanks

    #470087

    Fernando
    Free User
    Post count: 120

    Okay.
    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.

    #470088

    Paolo
    Site Admin
    Post count: 31206

    I’ve flagged your request for the developers.

    Thanks

    #470090

    Fernando
    Free User
    Post count: 120

    @paolo

    Thanks.

    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

    #470136

    Fernando
    Free User
    Post count: 120

    Also, please note that my add filter will be..
    add_filter(‘geodir_custom_fields’,’custom_myobject’,10,2);

    – Thanks

    #470214

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Did 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

    #470233

    Fernando
    Free User
    Post count: 120

    @stiofan

    Thanks 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

    #470268

    Fernando
    Free User
    Post count: 120

    @stiofan

    I 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.

    #470379

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    OK, 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

    #470538

    Fernando
    Free User
    Post count: 120

    @stiofan

    My 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.

    #470635

    Fernando
    Free User
    Post count: 120

    Hi,

    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.

Viewing 12 posts - 1 through 12 (of 12 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket