'default value' in custom fields

This topic contains 8 replies, has 3 voices, and was last updated by  Mitch Canton 4 years, 8 months ago.

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

Open Support Ticket

Tagged: ,

  • Author
    Posts
  • #503528

    Mitch Canton
    Expired Member
    Post count: 167

    I’m trying to understand how something works.

    I’m expecting that if I place content (words, but maybe a shortcode?) in the Places > Settings > Custom Fields > (field) > ‘default value’ input box

    then that information would automatically display under the (field’s) tab on any of the Place listings that had a package that displayed the (field), UNLESS other content was placed directly in a Place Listing (field’s) metabox, then the metabox content would override the default content.

    This doesn’t seem to work as I expected, so I’m trying to figure it out.

    Ultimately, I’d like to place an Advanced Custom Field shortcode [acf field=” “] in a WPGD custom field as a ‘default value’ so if the ACF field had data, it would display, but if it didn’t the (field) tab display would be empty (or the tab wouldn’t even show).

    Can something like this work?

    Thanks.

    #503529

    Guust
    Moderator
    Post count: 29970

    You cannot add shortcodes to a custom field that users can edit, that would be a major security risk, so that is not possible by default with WordPress.

    Thanks

    #503530

    Mitch Canton
    Expired Member
    Post count: 167

    Hey Guust,

    Thank you for the timely reply. Of course, I agree and understand. But if it was an “admin only” shouldn’t that work.

    I have another WPGD custom field where I use shortcode and it works fine.

    I just can’t get the default value part (in an admin only field) working if I want to use a shortcode there.

    Thanks.

    #503608

    Alex Rollin
    Moderator
    Post count: 27815

    The “Default value” is shown on the load of the form for the place. If nothing else is entered, then it is stored to the database. Setting the default will not automatically go and store that value for all previous listings. They would need to be edited and re-saved for each listing.

    If you are trying to do this with price package controls, we have a snippet to hide a tab based on package here: https://wpgeodirectory.com/docs-v2/addons/pricing-manager/#hide

    Instead of using a user field you could add this as a shortcode in a tab. I head you saying you might want to override it, so, that may not work for you, but it’s an idea that might help.

    #503766

    Mitch Canton
    Expired Member
    Post count: 167

    Hey Alex,

    OK, I appreciate the detail, maybe I am just not understanding the usage of ‘default value’.

    So I place text or shortcode in the default value input box in Places > Settings > Custom Fields > (field) > ‘default value’ input box

    I then go into admin and CREATE a new record, leaving that field’s input box empty (and since it is Admin Only, a user could not change it either).

    When I go to the new record on the front end, the tab associated with that field does NOT display. I would have thought it should display with the default value content?

    I then go into the new record and edit it (adding some test profile content). The ‘Profile’ tab now shows (because it has content where it didn’t before), but the tab for the field with the default value still does NOT show.

    I confirmed that the listing has a package which would include the default value field in question.

    I try this process with a different field (Places > Settings > …), setting a default value for it just to test, and I get the same result.

    I then manually add content into the field input box in the admin edit screen and save it, and that content DOES display on the listing on the front end after edit.

    To me, it looks like content placed in the ‘default value’ input box is not actually being displayed on a listing, even after creating New Listings or editing existing listings.

    But I may be totally missing something on default value usage?

    And thanks for the link on hiding tabs display.

    #503770

    Alex Rollin
    Moderator
    Post count: 27815

    It works for me with GD Shortcodes. Fields will not save HTML for default content. I would have to check with the developers about that but it seems reasonable. I was able to save a GD shortcode in a textarea, though, as default, and at least on the backend it saved without editing it.

    Please share your site’s details so we can check the issue. Be sure to share what CPT, field, etc.

    #503846

    Mitch Canton
    Expired Member
    Post count: 167

    Of note, I went in and added a new textarea field, placed a default value in it, then added a new gd_place listing, and it worked properly to display all the default values (the new textarea and the text and shortcode fields I previously placed) in the new listing.

    I did then go back in and edit a couple of existing listings, but when saving those changes, the default values of existing fields (that were empty in admin of these listing) did not display in the edited listing front end.

    (I cleared all caches to make sure it wasn’t a cache issue).

    At this point, I’m simply going to go with knowing default value works with new listings. I’d like to get it where edits to listings will add the default value if it’s been placed in a field settings (and is empty in the edited listing). I’ll continue to mess around and see what I can get done there and will update with site details.

    Thanks.

    #503906

    Alex Rollin
    Moderator
    Post count: 27815

    Yes, I found the same in my testing. As I mentioned, this is not the approach if you are looking to adjust some content on the page for a bunch of listings at once, not the recommended approach. Better to bulk update but again, not the recommended approach. Code should go in the display layer, and if needed get a quality advanced builder or 3rd party plugin to manage the custom visibility conditions you want.

    #503982

    Mitch Canton
    Expired Member
    Post count: 167

    Agreed. I’m just trying to figure out what does and doesn’t work for creating best practices on our workflow.

    We’ll add default values as needed, and use export/import for mods.

    Thanks for your help. Have a great day.

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

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

Open Support Ticket