• Resolved speedyp

    (@speedyp)


    I’m trying to create some input options for users where they can enter things like a product price and product description.

    I’ve tried various plugins, the latest being Just Custom Fields.

    The problem is that although I can create the fields and they show in the post edit page, if I enter a value it disappears when updating the post and doesn’t show on the published post.

    I feel I must be missing something very basic, but I’ve wasted a whole morning on this and getting nowhere, so any help or advice would be great – Thanks

Viewing 13 replies - 1 through 13 (of 13 total)
  • This is because it is not getting saved into database,
    i personally use ACF (http://www.advancedcustomfields.com/) they are like custom fields but more powerful and more flexible with good tutorial documentation/wiki to help you setup

    Thread Starter speedyp

    (@speedyp)

    Thanks Robin.

    Yeah, I tried ACF first. Followed all the info I could find, created a new field group but wp threw an error for the plugin when trying to publish new posts. Fixed that by registering the new fields in the functions.php. Also created a custom post type and added the php ACF suggested. But the common problem I seem to have is any value you add to a custom field just disappears when saving or publishing a post, and never shows on the post, unless I’ve set a default value for it.

    Must be something basic I’m just not getting.

    as such with ACF u should not to go and do manual work on functions.php (always had worked perfectly for me)

    Someone has suggested this fix try it out

    1. Open file – plugins\advanced-custom-fields\core\actions\input_save.php
    2. Go to line number “78”
    3. Comment out the line like so
    //’id’ => null,
    4. Save!

    Thread Starter speedyp

    (@speedyp)

    Hadn’t seen that Robin – I’ll give it a try, but it will have to wait a bit

    Thanks

    I did a project sometime back where i added extra fields if the above doesnt work you can take a cue from this code

    [ Moderator note: Please use backticks or the code button for code. It make the code much more readable. ]

    add_action( 'show_user_profile', 'extra_user_profile_fields' );
    add_action( 'edit_user_profile', 'extra_user_profile_fields' );
    
    function extra_user_profile_fields( $user ) { ?>
    <h3><?php _e("Extra profile information", "blank"); ?></h3>
    
    <table class="form-table">
    <tr>
    <th><label for="gender"><?php _e("Gender"); ?></label></th>
    <td>
    <input type="text" name="gender" id="gender" value="<?php echo esc_attr( get_the_author_meta( 'gender', $user->ID ) ); ?>" class="regular-text" />
    
    <span class="description"><?php _e("Enter your Gender."); ?></span>
    </td>
    </tr><tr>
    <th><label for="designation"><?php _e("Designation"); ?></label></th>
    <td>
    <input type="text" name="designation" id="designation" value="<?php echo esc_attr( get_the_author_meta( 'designation', $user->ID ) ); ?>" class="regular-text" />
    <span class="description"><?php _e("Please enter your designation."); ?></span>
    </td>
    </tr></table>
    <?php }
    
    add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
    add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
    
    function save_extra_user_profile_fields( $user_id ) {
    
    if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
    
    update_user_meta( $user_id, 'gender', $_POST['gender'] );
    update_user_meta( $user_id, 'designation', $_POST['designation'] );
    }
    Thread Starter speedyp

    (@speedyp)

    Hey Robin

    Had another go, re-installed ACF but same error,
    ‘Fatal error: Call to a member function update_value() on a non-object in /homepages/44/d424921357/htdocs/wp-content/plugins/advanced-custom-fields/acf.php on line 721’

    and it doesn’t seem to have the file you indicated earlier?

    “Open file – plugins\advanced-custom-fields\core\actions\input_save.php”

    Maybe that’s the problem? Just installed it through the wp dash.

    Thread Starter speedyp

    (@speedyp)

    taking a look now………….

    Thread Starter speedyp

    (@speedyp)

    …….. good grief! Way out of my depth here.

    Thought it would be easy to add a “price” field to my posts, but maybe not.

    Probably going to have to stick with my original option of woocommerce or marketpress.

    But thanks for trying to help 🙂

    Cheers

    It works fine for me all the time 🙁 not sure where the problem is coming for u

    if u want to add only two fields its not worth installing woocommerce or marketplace
    use a simple shopping cart plguin — http://getshopped.org/

    Thread Starter speedyp

    (@speedyp)

    Bit of a breakthrough (I think).

    1. Created a field group with 1 field (price) as text input & saved
    2. Selected create php option in settings & added code to functions.php
    3. Added ‘<h1><?php the_field(‘price’); ?></h1>’ to my post template

    Ended up with 2 price fields! But at least saving the post didn’t crash. Deleted the original field I created to remove the second price entry & it seems to be working………..

    Thread Starter speedyp

    (@speedyp)

    🙂

    Great i am glad it sorted out 🙂

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Need help with custom fields’ is closed to new replies.