ACF error Child theme

Good evening
I tried to add in the child theme the custom field but but something does not work.

Custom field:

<?php

// =============================================================================
// VIEWS/ETHOS/WP-SINGLE.PHP
// -----------------------------------------------------------------------------
// Single post output for Ethos.
// =============================================================================

$fullwidth = get_post_meta( get_the_ID(), ‘_x_post_layout’, true );

?>

<?php get_header(); ?>
    <?php while ( have_posts() ) : the_post(); ?>
      <?php x_get_view( 'ethos', 'content', get_post_format() ); ?>
        <p><?php the_field('libreria'); ?></p>
      <?php x_get_view( 'global', '_comments-template' ); ?>
    <?php endwhile; ?>
    
  </div>
  <?php if ( $fullwidth != 'on' ) : ?>
    <?php get_sidebar(); ?>
  <?php endif; ?>
</div>
<?php get_footer(); ?>

My child theme:

<?php

// =============================================================================
// FUNCTIONS.PHP
// -----------------------------------------------------------------------------
// Overwrite or add your own custom functions to X in this file.
// =============================================================================

// =============================================================================
// TABLE OF CONTENTS
// -----------------------------------------------------------------------------
// 01. Enqueue Parent Stylesheet
// 02. Additional Functions
// =============================================================================

// Enqueue Parent Stylesheet
// =============================================================================

add_filter( ‘x_enqueue_parent_stylesheet’, ‘__return_true’ );

// Displaying Excerpt in Recent Posts
// =============================================================================

function x_shortcode_recent_posts_v2( $atts ) {
extract( shortcode_atts( array(
‘id’ => ‘’,
‘class’ => ‘’,
‘style’ => ‘’,
‘type’ => ‘post’,
‘count’ => ‘’,
‘category’ => ‘’,
‘offset’ => ‘’,
‘orientation’ => ‘’,
‘show_excerpt’ => ‘true’,
‘no_sticky’ => ‘’,
‘no_image’ => ‘’,
‘fade’ => ‘’
), $atts, ‘x_recent_posts’ ) );

$allowed_post_types = apply_filters( ‘cs_recent_posts_post_types’, array( ‘post’ => ‘post’ ) );
$type = ( isset( $allowed_post_types[$type] ) ) ? $allowed_post_types[$type] : ‘post’;

$id = ( $id != ‘’ ) ? ‘id="’ . esc_attr( $id ) . ‘"’ : ‘’;
$class = ( $class != ‘’ ) ? ‘x-recent-posts cf ’ . esc_attr( $class ) : ‘x-recent-posts cf’;
$style = ( $style != ‘’ ) ? ‘style="’ . $style . ‘"’ : ‘’;
$count = ( $count != ‘’ ) ? $count : 3;
$category = ( $category != ‘’ ) ? $category : ‘’;
$category_type = ( $type == ‘post’ ) ? ‘category_name’ : ‘portfolio-category’;
$offset = ( $offset != ‘’ ) ? $offset : 0;
$orientation = ( $orientation != ‘’ ) ? ’ ’ . $orientation : ’ horizontal’;
$show_excerpt = ( $show_excerpt == ‘true’ );
$no_sticky = ( $no_sticky == ‘true’ );
$no_image = ( $no_image == ‘true’ ) ? $no_image : ‘’;
$fade = ( $fade == ‘true’ ) ? $fade : ‘false’;

$js_params = array(
‘fade’ => ( $fade == ‘true’ )
);

$data = cs_generate_data_attributes( ‘recent_posts’, $js_params );

$output = “<div {$id} class=”{$class}{$orientation}" {$style} {$data} data-fade="{$fade}" >";

$q = new WP_Query( array(
  'orderby'             => 'date',
  'post_type'           => "{$type}",
  'posts_per_page'      => "{$count}",
  'offset'              => "{$offset}",
  "{$category_type}"    => "{$category}",
  'ignore_sticky_posts' => $no_sticky
) );
if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();
  if ( $no_image == 'true' ) {
    $image_output       = '';
    $image_output_class = 'no-image';
  } else {
    $image              = wp_get_attachment_image_src( get_post_thumbnail_id(), 'entry-cropped' );
    $bg_image           = ( $image[0] != '' ) ? ' style="background-image: url(' . $image[0] . ');"' : '';
    $image_output       = '<div class="x-recent-posts-img"' . $bg_image . '></div>';
    $image_output_class = 'with-image';
  }

$cat = get_the_category();
$category = $cat[0]->name;
  $excerpt = ( $show_excerpt ) ? '<div class="x-recent-posts-excerpt"><p>' . preg_replace('/<a.*?more-link.*?<\/a>/', '', cs_get_raw_excerpt() ) . '</p></div>' : '';
  $output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( csi18n('shortcodes.recent-posts-permalink'), the_title_attribute( 'echo=0' ) ) ) . '">'
             . '<article id="post-' . get_the_ID() . '" class="' . implode( ' ', get_post_class() ) . '">'
               . '<div class="entry-wrap">'
                 . $image_output
                 . '<div class="x-recent-posts-content">'
    				. '<span style="margin-bottom: 10px;" class="x-recent-posts-date">' . $category . ' </span>'
                   //. '<span style="margin-bottom: 10px;" class="x-recent-posts-date">' . get_the_date() . ' ' . $category . ' </span>'
                   . '<h3 class="h-recent-posts">' . get_the_title() . '</h3>'
                    . $excerpt
                 . '</div>'
               . '</div>'
             . '</article>'
           . '</a>';
endwhile; endif; wp_reset_postdata();

$output .= ‘

’;

return $output;

}

add_filter(‘wp_head’, ‘custom_recent_posts’);

function custom_recent_posts() {
remove_shortcode( ‘x_recent_posts’ );
remove_shortcode( ‘recent_posts’ );
add_shortcode( ‘x_recent_posts’, ‘x_shortcode_recent_posts_v2’ );
add_shortcode( ‘recent_posts’, ‘x_shortcode_recent_posts_v2’ );
}

// Mostrare immagini delle categorie
// =============================================================================

add_filter(‘body_class’,‘add_category_to_single’);
function add_category_to_single($classes) {
if (is_single() ) {
global $post;
foreach((get_the_category($post->ID)) as $category) {
// add category slug to the $classes array
$classes[] = $category->category_nicename;
}
}
// return the $classes array
return $classes;
}

// Frecce Categoria
// =============================================================================

function x_entry_navigation() {

$stack = x_get_stack();

if ( $stack == ‘ethos’ ) {
$left_icon = ‘’;
$right_icon = ‘’;
} else {
$left_icon = ‘’;
$right_icon = ‘’;
}

$is_ltr = ! is_rtl();
$prev_post = get_adjacent_post( true, ‘’, false );
$next_post = get_adjacent_post( true, ‘’, true );
$prev_icon = ( $is_ltr ) ? $left_icon : $right_icon;
$next_icon = ( $is_ltr ) ? $right_icon : $left_icon;

?>

<?php if ( $prev_post ) : ?>
  <a href="<?php echo get_permalink( $prev_post ); ?>" title="<?php __( 'Previous Post', '__x__' ); ?>" class="prev">
    <?php echo $prev_icon; ?>
  </a>
<?php endif; ?>
<?php if ( $next_post ) : ?>
  <a href="<?php echo get_permalink( $next_post ); ?>" title="<?php __( 'Next Post', '__x__' ); ?>" class="next">
    <?php echo $next_icon; ?>
  </a>
<?php endif; ?>
<?php

}

// Sidebar Categoria //

function assign_custom_sidebar($sidebar){

if (is_singular('post')) {
    $categories = get_the_category(); 
    $mycat = array();
    foreach($categories as $category) {
        $mycat[] =  $category->cat_name;
    }
    if (in_array("CUCINA",$mycat) ){
        return 'ups-sidebar-news';        
    } elseif (in_array("ARTE",$mycat)){
        return 'ups-sidebar-news';        
    } elseif (in_array("LAB",$mycat) ){
        return 'ups-sidebar-news';               
    }
}

return $sidebar;
}
add_filter( ‘ups_sidebar’, ‘assign_custom_sidebar’);

Thank you for your precious help

Hi @fra_fantasy,

Thanks for writing in.

Would you mind sharing us more details on what you created or what you want to achieve so we could easily trace the customization.

Thank you so much.

I installed ACF PRO Custom fields, on front end but it is not showing.
I read this guide: https://theme.co/apex/forum/t/integrated-plugins-acf-pro/49

but on adding the php in the child theme something does not work.

How do we fix it?
Thanks! :relaxed:

Hey @fra_fantasy,

You’re using this code <p><?php the_field('libreria'); ?></p> and based on your screenshot it is the group’s name? What field in the group you’re trying to display? If you want to display all of the fields, try following this guide.

Thanks.

I’m looking for a solution to facilitate my client to insert photos + book descriptions.
is there an easier solution? I can not make them use the pro editor.

Hello There,

There is no easier solution. You will have to code the fields into the wp-single.php file so that it will be displayed automatically. Please follow the guide as shown here: https://www.advancedcustomfields.com/resources/group/ to display the fields in the group. This is the only way to display ACF.

Hope this helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.