Search code examples
phpwordpressadvanced-custom-fields

ACF - displaying specific data on a page without having to hardcode the php


I have a custom post type, which contains some "posts". These "posts" have ACF attached to them. I would like to display some of this information on a regular page, but I do not know how to reference the ACF from within the WordPress editor.

I could make a .php template for the specific page, but that would cost a lot of time since I would need to make multiple page templates and hardcode all the text, images etc into it. It would be an even bigger pain to manage it.

So, to sum up, I would like to display specific ACF information taken from a custom post type on a regular page using default WordPress editor.

If that isn't possible, what are the alternatives.

Thank you.

Custom post type - Rooms contain:

  • Room 1 - ACF -> short description, long description
  • Room 2 - ACF -> short description, long description
  • Room 3 - ACF -> short description, long description
  • Room 4 - ACF -> short description, long description
  • etc

On a regular page I would like to display short description (for example).


Solution

  • You can absolutely use the editor with ACf's built-in shortcodes. You can reference https://www.advancedcustomfields.com/resources/shortcode/ but the gist is if the field is on that post you can query like this:

    [acf field="fieldname"] and if you wanted to query from another post it would be [acf field="fieldname" post_id="123"]