Home Forums General Issues Create and Fill Out Fields on Post Edit Screen, Then Display them with Shortcode


Create and Fill Out Fields on Post Edit Screen, Then Display them with Shortcode

  • Is it possible to assign fields to a custom page template, then let the user fill out the fields like usual, but then have them drop a custom short code into the post content itself (as opposed to displaying the fields through the page template’s PHP?)

    Just to paraphrase, I want the user to fill out custom fields on the post edit screen to have the values they want, and then I want them to be able to drop a [custom-shortcode] into the content that will then use the values to create a comparison table or whatever.

    The reason for this is that I don’t want them to have to use multiple WYSIWYG text boxes with custom fields in between, kind of replicating the layout of the page like you’d get in Gutenberg (this is the classic editor I’m talking about). The main reason is the client also wants a Table of Contents plugin and I know they need to run through the_content to generate the table.

    They have Shortcodes Ultimate installed but there’s no way I’m going to be able to do it that way with dynamic values in the shortcode. I’d like for the shortcode to simply contain all the HTML and pull the values from the post ID, then spit it back out with nothing more than [custom-shortcode].

    Thanks for your help and insight!

  • ACF has shortcodes that work for simple fields

    This will not work for complex fields and you’d need to build your own custom shortcodes to do what you want.

  • @hube2
    I saw something on Stack Overflow about writing some function to copy everything in ACF for a post over to the normal the_content(), and that would allow these Table of Contents plugins to continue to function (since they can’t read ACF fields).

    It was using some ACF filter like “full-text” to copy over to the normal database table for post content. Do you know if this would run through all of the fields in order and copy them in order? If I could do that, the Table of Contents plugins could still read the headers in order.

    What a pain. I’m likely going to have to tell the client that his expectations aren’t going to align with reality.

  • If you are talking about this plugin it says that there are filters and hooks, but I don’t see any information on them. I would talk to them. If it’s another plugin then you can try contacting the author.

    There are ways to insert ACF fields into the content, but that would really mean that you’d hide the content editor, then create an acf/save_post filter that would parse all the fields, created all the needed HTML and then update the post with the new content. Likely a complex project, but possible.

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

You must be logged in to reply to this topic.