• Resolved wprat

    (@wprat)


    Hello.
    I tried to add instruction – general syntax follows – <?php the_field(‘FIELD_NAME’); ?> in single.php template, as suggested in many guides accessible on web. Tried to add in other Kadence templates too, with no luck. There is no problem with Astra theme. So, where exactly should I put instruction mentioned above in Kadence?
    Many thanks and best regards, wprat

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi there,

    Can you clarify what you are trying to achieve with the ACF function? Maybe send us a quick screen recording of what you want to accomplish?

    I do not suggest you override the single.php as there is a lot going on in terms of hooks and how the content and all the sub-templates files area loaded into the page. Using the hooks made available through WordPress hooks functions and the Kadence Theme you can hook in your custom fields anywhere without having to override templates and potentially break the makeup of the pages.

    I’m happy to offer some help pointing you in the right direction for using hooks. I’m not entirely sure what you are going for but I’ll give you an example that may help you and then you can ask follow up if needed.

    I suggest you use a Code Snippet plugin so you could safely add something like this: https://kadence-theme.com/knowledge-base/advanced/how-to-add-a-custom-filter-or-function-with-code-snippets/

    Let’s say you want to add a custom meta field before the excerpt content for archives of a custom post type you’ve created with the slug custom-post-type.

    add_action( ‘get_template_part_template-parts/content/entry_summary’, ‘custom_add_fields_before_excerpt’ );
    function custom_add_fields_before_excerpt() {
    if ( ‘custom-post-type’ === get_post_type() ) {
    the_field( ‘custom_field’ );
    }
    }

    without needing to create a new function if you wanted this same custom field to output before the post content of your single post page you could add this action:

    add_action( ‘get_template_part_template-parts/content/entry_content’, ‘custom_add_fields_before_excerpt’ );

    I hope this helps and let us know how we could help you further.

    Kind Regards,
    Michael

    Thread Starter wprat

    (@wprat)

    Dear Michael, You are really kind, many thanks for Your support.
    But, my use case is rather simple (because I am in learning process). Let me explain:
    1. There is Kadence theme; then I installed ACF (only custom fields are needed, not custom posts).
    2. I created one Field Group with three simple textual custom fileds inside, set relation Post type is equal to Post (as ACF expect from user to do).
    3. Created new post, wrote some text and populate custom fields with short data.
    4. Now, I have to configure Kadence theme so whole post (with data entered in custom fields) will be able to display in user browser. Whatewer I tried, I missed!
    So, question is: How to display custom fileds in Kadence posts so user can see this data?!?

    best regards,
    wprat

    Hello @wprat,

    Just to confirm, do you want to show the value of the ACF fields on a certain part of the post layout? If so, you can do that by using the Pro feature Element Hooks and showing the values of the ACF fields using their shortcodes.

    This way, you’ll just have to create a single element, set the placement, and display settings to show it on all single posts at a specific place within the current layout.

    Hope this gave you further insights on how to achieve your requirement.

    Kind Regards,
    Karla

    Thread Starter wprat

    (@wprat)

    your effort is appreciated, karlalevelup, but…

    … I know about ACF shortcodes, this is only partial solution. Please, look at the article https://kinsta.com/blog/advanced-custom-fields, chapter How to Add Advanced Custom Fields in Theme Template Files. My question is: How to add ACF in Kadence template file and I ask that question because Kinsta’s proposed solution – <?php the_field(‘FIELD_NAME’); ?> – do not work in Kadence theme. That is the point.

    best regards,
    wprat

    Hello @wprat,

    I apologize for the previous suggestion.

    So if you want to directly add that code, you’ll need to use a child theme.

    Then, copy the kadence/template-parts/content/single-entry.php file to the same path in your child theme(kadence-child/template-parts/content). This is the file where you can add your code for showing the ACF field value.

    Kind Regards,
    Karla

    Thread Starter wprat

    (@wprat)

    yup-yup, many thanks, dear karlalevelup
    and best wishes to all of you from Kadence team
    wprat

    Thread Starter wprat

    (@wprat)

    Uh-uh, sorry for bothering, but there is a problem with suggested single-entry.php. I followed your recommendations and added the custom fields code above this php statement:

    </article><!-- #post-<?php the_ID(); ?> -->

    Everything works BUT custom fields are displayed in posts AND PAGES. As mentioned in one of comments above I want / need to display custom fields in POSTS only. Do you have any suggestion how to resolve this?

    many thanks
    wprat

    • This reply was modified 3 years, 4 months ago by wprat.

    You can add a check in your code:

    if ( 'post' === get_post_type() ) {
    the_field( 'custom_field' );
    }

    Ben

    Thread Starter wprat

    (@wprat)

    That’s it! Many thanks and stay well!
    wprat

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Posts template and Custom fields’ is closed to new replies.