Support

Account

Home Forums Front-end Issues Custom Taxonomy With Text Input

Solving

Custom Taxonomy With Text Input

  • Sorry if this questions is inconsistent with plugins or forum? Its a great plugins. Now I have a custom taxonomy named “Rent”, unfortunately I need to takes its value as text from frontend, means people can fill their rent amount in frontend for new post.
    I don’t know PHP, know something in HTML, I change some code of your taxonomy.php file. I add

    
    elseif( $this->field['field_type'] == 'text' )
    		{
    			$output = '<li><label class="selectit"><input type="text" name="' . $this->field['name'] . '" value="" ' . ($selected ? 'readonly="readonly"' : '') . ' autocomplete="off" /> </label></li>';
    			
    		}
    with "function start_el ()" and add 
    'text' => __('Text', 'acf')
    with option choices.
    

    that take input for tags from frontend, but not for custom taxonomy “Rent”.
    Is it possible ?
    I am very very pleased if you answer me.

  • Hi @shatilarefin,

    Can you please wrap your code in backticks so it is formatted and easier to read.

    I am not 100% sure what you are asking here but it sound like you want to be able to let your customers input their own data. This is not a simple change and you will need to be confident with PHP to achieve this functionality.

    Here is a good place to start => http://www.advancedcustomfields.com/resources/getting-started/displaying-custom-field-values-in-your-theme/

    Good luck. 🙂

  • I know how to display “custom fields” or “custom taxonomy”, question about how to insert data into “custom taxonomy” from frontend. Their is any javascript function or anything. Its too complex, …

  • Hi @shatilarefin

    ACF provides some basic support for submitting data from the front end. You can read about it here:
    http://www.advancedcustomfields.com/resources/tutorials/using-acf_form-to-create-a-new-post/

    If you wish to code this manually, you can use the update_field function:
    http://www.advancedcustomfields.com/resources/functions/update_field/

    There is no JS function to get, or update a value. Only PHP functions are available.

    Thanks
    E

  • I add bellow code to the theme function.php

    $post = array(
            'post_status'  => 'publish',
            'post_title'  => $_POST["fields"]['field_52e6af7f6f4b8'] ,
    	'post_content' => $_POST["fields"]['field_52e6af906f4b9'],
            'post_type'  => 'post' 
         );  
     
        // insert the post
        $post_id = wp_insert_post( $post ); 
        
        update_field('field_52e6afd36f4bc', $_POST['field_52e6afd36f4bc'], $post_id);
    
        // update $_POST['return']
        $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );    
     
        // return the new ID
        return $post_id;
    }

    where “field_52e6afd36f4bc” is the field key of custom taxonomy “rent”. I don’t understand what is update_field()’s $value for frontend new post, where user insert a value, not like the example- $value=”some string”.

    And where I put update_field(), into function.php or templete.php.

  • Hi @shatilarefin

    I have a few questions regarindg your code:
    1. The code should be wrapped in a filter for acf/pre_save_post
    2. This is a filter for the acf_form function
    3. Are you using the acf_form function?
    4. If so, what $options are you using in the acf_form function?
    5. Have you debugged your code?
    6. There is an issue with your code: $_POST['field_52e6afd36f4bc'] should be $_POST['fields']['field_52e6afd36f4bc']

    Thanks
    E

  • 1. don’t understand
    2. understand
    3. yes
    4. in attachment
    5. yes
    6. understand

    Its complicated, I have a second thought, its easily define title of a post by using 'post_title' => $_POST["fields"]['field_52e6af7f6f4b8']
    As like this, can I define field for custom taxonomy “rent”, 'rent' => $_POST["fields"]['field_52e6afd36f4bc'] or for post Tags 'post_tag' => $_POST["fields"]['field_52ee3572071cd']
    where field_52e6afd36f4bc or field_52ee3572071cd is custom text field.
    If second thought is possible, first is dismissed.

    Thanks for holiday replay.

  • Hi @shatilarefin

    Your field key for ‘rent’ is different to the code you have posted above. Please double check that your field keys are correct.

    To better understand that acf/pre_save_post filter, you can read this tutorial:
    http://www.advancedcustomfields.com/resources/tutorials/using-acf_form-to-create-a-new-post/

    Thanks
    E

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

The topic ‘Custom Taxonomy With Text Input’ is closed to new replies.