Forums

[resolved] Need help with custom fields (14 posts)

  1. speedyp
    Member
    Posted 9 months ago #

    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

  2. cinghaman
    Member
    Posted 9 months ago #

    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

  3. speedyp
    Member
    Posted 9 months ago #

    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.

  4. cinghaman
    Member
    Posted 9 months ago #

    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!

  5. speedyp
    Member
    Posted 9 months ago #

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

    Thanks

  6. cinghaman
    Member
    Posted 9 months ago #

    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'] );
    }
  7. speedyp
    Member
    Posted 9 months ago #

    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.

  8. cinghaman
    Member
    Posted 9 months ago #

  9. speedyp
    Member
    Posted 9 months ago #

    taking a look now.............

  10. speedyp
    Member
    Posted 9 months ago #

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

  11. cinghaman
    Member
    Posted 9 months ago #

    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/

  12. speedyp
    Member
    Posted 9 months ago #

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

  13. speedyp
    Member
    Posted 9 months ago #

    :)

  14. cinghaman
    Member
    Posted 9 months ago #

    Great i am glad it sorted out :)

Reply

You must log in to post.

About this Topic

Tags

No tags yet.