Hello I’m not able to use acf value from cpt or category on my category.php
<?php
$current_category = get_queried_object();
$cat_id = $current_category->term_id;
$query = new WP_Query(
array(
'posts_per_page' => -1,
'post_type' => 'lifte', // you can change it according to your custom post type
'cat' => $cat_id ,
)
);
if ( $query->have_posts() ) :
while ( $query->have_posts() ) :
$query->the_post();
$technical_data = get_field('technicalData') ;
the_title();
echo $technical_data['drivingForce'];
endwhile;
wp_reset_postdata();
endif;
?>
I get this error “Warning: Illegal string offset ‘drivingForce’ ”
What is wrong?
What kind of field is technicalData
, are you sure the name is correct? I’m guessing that its a group field(?)
$technical_data = get_field('technicalData') ;
var_dump($technical_data);
Yes it is a group field
It was a conflict with this code when I deleted this it works fine.
function ringstedlift_add_custom_types( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
'post', 'nav_menu_item', 'lifte',
));
return $query;
}
}
add_filter( 'pre_get_posts', 'ringstedlift_add_custom_types' );
The problem is that you are filtering queries with that filter that you do not want to query.
if (!$query->is_main_query()) {
return;
}
you may also need to test for other things.
I have dropped this code because I have chosen to make a custom category.php