Support

Account

Home Forums General Issues ACF Fields displaying on front end

Solving

ACF Fields displaying on front end

  • I’ve been using ACF to build customised page templates for a while quite happily, but I need to use it now to build post templates as a simple events system.
    I installed Single-Post-Templates plugin and created an single-event.php template within my child theme folder. I created the ACF Field Group and found there were 2 “Post Template” options in the dropdown for location rules. The first is the WP one iwth just a default template option but the second was the plugin option and this allowed me to select the event-single template. So far, so good.
    I build my field options and published, and on the post there was an option to select the single-event template which, when I did, displayed the ACF fields as expected. Great…
    I filled in the fields, published the post and viewed it, which is where things started to get weird. I have comments enabled and between the comment textbox and the submit button on the front-end post, all the ACF Fields display (empty)??!!
    If I disable comments on that post, the comments form and all the ACF fields disappear so it’s the comment form calling those fields somehow but I can’t figure out how?? Does ACF share a variable with the comments.php file?

    Any help appreciated, it’s driving me nuts. I’ve removed the fields with CSS display: none but that’s just a mask, not a fix…

  • Hi @neo2810

    It seems there’s a misconfiguration in your settings. Could you please share the JSON or XML export file so I can check your setting and test it on my installation?

    Thanks 🙂

  • Thanks James,

    JSON attached

  • Hi @neo2810

    Thanks for sharing the export file.

    I’ve just checked it and it seems you have a custom location rule set on it. Could you please share the code to add the location rule?

    Also, kindly make sure that you have the correct match rule. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/custom-location-rules/.

    Thanks 🙂

  • Hi James,

    I have “Post Template equal to event-single”. Event-single is a single post template.

  • Hi @neo2810

    From what I saw in your export file, the rule is set to:

    {
        "param": "cpt",
        "operator": "==",
        "value": "single-events.php"
    }

    Where it should be something like this:

    {
        "param": "post_template",
        "operator": "==",
        "value": "single-events.php"
    }

    That’s why I said that it seems you have a wrong rule. Could you please check your custom location again?

    Thanks 🙂

  • That’s correct, I’m using in the Single Post Template plugin which adds its own entry to the location dropdown (“cpt”) to add the Post Template option to the Single Post admin page. I saw no built in option to do that and my PHP knowledge is intermediate so I didn’t know how to code it myself. If there is a better way to do it without using a plugin, I’m all ears 🙂

  • Hi @neo2810

    I’m not sure how Single Post Template plugin works, but because the option is not created by ACF, I can’t help you much because I don’t know how it’s set. Kindly get in touch with their support for further information.

    Another option you can do is to set the exact post you want the field group to show up. You can also create a custom taxonomy for your blog post and set the field group to that taxonomy. That way you can simply assign the post to the custom taxonomy to show the custom fields. I’ve attached a screenshot for your reference.

    I hope this make sense 🙂

  • Thanks James, but neither of those would work. I need to be able to write a PHP template to display the post contents and the form contents on each generated post in the category. I need to use Post Template = “and” Post category = to control that.

    Is there a way to write in the post template selection dropdown into the admin section of the post page and link it to ACF’s Post Template location rule without using the Single Post plugin?

  • Hi @neo2810

    I believe ACF has the rule to set the post template. I’ve attached a screenshot for your reference.

    If somehow you still can’t use this rule, you can always create a new location rule by following this guide: https://www.advancedcustomfields.com/resources/custom-location-rules/.

    I hope this helps 🙂

  • Setting the location rule isn’t the issue. There’s no mechanism on the actual post page to call the template, rule or no rule. That’s why you either need the plugin to add that function, or write it in yourself.

  • Hi @neo2810

    Yes, you are correct. But please keep in mind that the blog posts are not supposed to have a template. If you need to use a template on a blog post, then it falls into a customization category. Because ACF won’t know what kind of method used by your custom code or plugin, it won’t be able to support it. That’s why if the original rule doesn’t work; you need to add it yourself or ask the plugin author about it.

    I hope this makes sense 🙂

  • I found this thread interesting though it’s completely different from the topic I was searching for. I had to read it a couple of times to understand what was going on and it still isn’t totally clear… but the jist of it is that Single Post Templates provides a custom location setting which is almost the right fit for what you’re doing, but not quite. Well that’s the challenge anytime with plugins, I couldn’t imagine trying to build a site without doing at least some coding. Ideally you’ll be able to get the original author of that plugin to modify the custom rule to suit you’re requirements, I’d suggest offering them money! If that doesn’t work, find another developer, offer them money. Bottom line is WP and ACF and many other plugins offer a lot for free, but there comes a time where you need to buy solutions.

    My firm (http://goldhat.ca) offers discounts on any projects we can later release, or bundle. We have 3 ACF-based plugins already in the WordPress.org directory. Would be happy to look at either adapting Single Post Templates or building a new version. I noticed that plugin not updated in 2-years, so it will be incompatible eventually with WP or ACF if it isn’t already.

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

The topic ‘ACF Fields displaying on front end’ is closed to new replies.