Support

Account

Home Forums General Issues Automating Shortcodes to ACF conversion Reply To: Automating Shortcodes to ACF conversion

  • Hi guys, I’m sorry for not being able to clearly explain the first time.
    I’ll try to complete my first post.

    This is the actual state of my website
    • the native WordPress content contains my before|after shortcode + my article.
    • an ACF flexible field is located right under, giving me access to my brand new ACF before|after fields

    ┌─────────────────────────────────────────────────────────────────────┐
    │Native WordPress Post Content                                        │
    │                                                                     │
    │                                                                     │
    │                                                                     │
    │This is where my actual shortcode is.                                │
    │                                                                     │
    │[taz_before_after large="yes" width="1200" height="800"              │
    │beforeimage="IMG_3164-RAW.jpg"]IMG_3164.jpg[/taz_before_after]       │
    │                                                                     │
    │                                                                     │
    │Noiram ego amore. Velisit eugiamconse diamcon cillum luctus pede     │
    │facincilit cor viverra, facincilit rcilis tempor. Vendiam verit      │
    │iliquiscipis eros doloboreet alis suscipit sagittis utate. Noiram ego│
    │amore. Velisit eugiamconse diamcon cillum luctus pede facincilit cor │
    │viverra, facincilit rcilis tempor. Vendiam verit iliquiscipis eros   │
    │doloboreet alis suscipit sagittis utate. Noiram ego amore. Velisit   │
    │eugiamconse diamcon cillum luctus pede facincilit cor viverra,       │
    │facincilit rcilis tempor. Vendiam verit iliquiscipis eros doloboreet │
    │alis suscipit sagittis utate.                                        │
    │                                                                     │
    └─────────────────────────────────────────────────────────────────────┘
                                                                           
    ┌─────────────────────────────────────────────────────────────────────┐
    │Fields Group (Flexible Content)                                      │
    │                                                                     │
    │                      ┌────────────────────────────────────────────┐ │
    │                      │Add new flexible content (ie. Before|After) │ │
    │                      └────────────────────────────────────────────┘ │
    │                                                                     │
    └─────────────────────────────────────────────────────────────────────┘

    This is what I would like to achieve:
    • Creating my Before|After comparison using my ACF fields
    • Removing my old shortcode

    ┌─────────────────────────────────────────────────────────────────────┐
    │Native WordPress Post Content                                        │
    │                                                                     │
    │       NO more comparison shortcode                                  │
    │Noiram ego amore. Velisit eugiamconse diamcon cillum luctus pede     │
    │facincilit cor viverra, facincilit rcilis tempor. Vendiam verit      │
    │iliquiscipis eros doloboreet alis suscipit sagittis utate. Noiram ego│
    │amore. Velisit eugiamconse diamcon cillum luctus pede facincilit cor │
    │viverra, facincilit rcilis tempor. Vendiam verit iliquiscipis eros   │
    │doloboreet alis suscipit sagittis utate. Noiram ego amore. Velisit   │
    │eugiamconse diamcon cillum luctus pede facincilit cor viverra,       │
    │facincilit rcilis tempor. Vendiam verit iliquiscipis eros doloboreet │
    │alis suscipit sagittis utate.                                        │
    │                                                                     │
    │                                                                     │
    │                                                                     │
    │                                                                     │
    │                                                                     │
    │                                                                     │
    │                                                                     │
    │                                                                     │
    └─────────────────────────────────────────────────────────────────────┘
                                                                           
    ┌─────────────────────────────────────────────────────────────────────┐
    │Fields Group (Flexible Content)                                      │
    │                                                                     │
    │  ┌───────────────────────────────────────────────────────────────┐  │
    │  │Before|After Fields Group                                      │  │
    │  │                                                               │  │
    │  ├──────────────┬────────────────────────────────────────────────┤  │
    │  │   Content    │        ┌─────────────────────────────────────┐ │  │
    │  ├─────────────┬┘ Title: │                                     │ │  │
    │  │   Options   │         └─────────────────────────────────────┘ │  │
    │  ├─────────────┤                                                 │  │
    │  │Adv. Options │                                                 │  │
    │  ├─────────────┤   Before Image             After Image          │  │
    │  │             │  ┌─────────────────┐      ┌─────────────────┐   │  │
    │  │             │  │                 │      │                 │   │  │
    │  │             │  │                 │      │                 │   │  │
    │  │             │  │                 │      │                 │   │  │
    │  │             │  │IMG_3164-RAW.jpg │      │   IMG_3164.jpg  │   │  │
    │  │             │  │                 │      │                 │   │  │
    │  │             │  │                 │      │                 │   │  │
    │  │             │  │                 │      │                 │   │  │
    │  │             │  │                 │      │                 │   │  │
    │  │             │  └─────────────────┘      └─────────────────┘   │  │
    │  └─────────────┴─────────────────────────────────────────────────┘  │
    │                                                                     │
    │                                                                     │
    │                                                                     │
    │                                                                     │
    └─────────────────────────────────────────────────────────────────────┘

    There is no issue doing this manually. I mean, going through all of my posts, one by one, and manually create a new ACF Before|After comparison, and then removing my old shortcode.
    The problem is time. I’ve hundreds of posts like this one, and I cannot afford to edit each of them manually.

    So I’m searching for a way that would allow me to automate this whole process.
    As said, I can easily extract and build a list of all my comparison shortcodes + post ID.
    The idea I had would be to make a function that would loop through this list, and add for each of my posts the related ACF before|after comparison.

    For now, I don’t need to delete the old shortcode on my post content. I’ll find a way later.

    Hope that’s more understandable now.