Advanced Custom Fields
[resolved] Can custom fields be *optional*? (3 posts)

  1. lucaslem
    Posted 3 years ago #

    I am 100% new to php so please forgive the ignorance in my question.

    I have followed directions and managed to get custom fileds into my template page. However, I wonder if there is some sort of code which can conditionally prevent a field from appearing if the value is left blank (or if value = "blank")

    An example to illustrate the functionality I am after: my client offers sports training. Each course he offers has a list of details (price, location, training duration, number of participants, etc...). Then there are certain trainings in which only a certain number of those fields apply (for example: a one-on-one training obviously excludes the need to specify number of participants)

    Is there a piece of code which could specify that if a certain field has a value of "blank" or "empty" (or even better, if it is just left blank in the dashboard), then that field will not appear?

    Currently, all my fields appear no matter what.

    Thanks in advance.


  2. lucaslem
    Posted 3 years ago #

    Perhaps I need to make a template for each type of training if they require different fileds, but I wanted to be sure there isn't some work around first.

  3. elliotcondon
    Plugin Author

    Posted 3 years ago #

    Hi @lucaslem

    These are called "conditional statements" - "if statements".

    Please jump onto the ACF website and read the docs / code examples to see this in action


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Advanced Custom Fields
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic