Support

Account

Home Forums Front-end Issues acf value from cpt not showing on category.php

Solved

acf value from cpt not showing on category.php

    • 10sen

    • June 6, 2019 at 6:20 pm

    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);
    
    • 10sen

    • June 8, 2019 at 4:41 am

    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.

    • 10sen

    • June 27, 2019 at 9:59 pm

    I have dropped this code because I have chosen to make a custom category.php

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.