Support

Account

Home Forums General Issues ACF Post Field and Taxonomy Issue

Unread

ACF Post Field and Taxonomy Issue

  • Hello, I’ve got a teaser snippet that pulls the taxonomy info for a custom post type and works fine when using a wpquery:

    setup_postdata($post);
    $postid = $post->ID;
    $item_image = get_field("listing_image", $post->ID);
    
        // TAXONOMY //
        $taxonomy = 'types';
        $terms = get_object_term_cache( $postid, $taxonomy );
        $outputpill = '';
        $i = 1;
    
        $teasertype = '';
        foreach($terms as $term) {
            if ($i == 2) { break; }
        if(!empty($outputpill))
            $outputpill .= '';
            $outputpill .= '<div class="cat cat-pill pill-'. $term->slug . '">'.$term->name.'</div>';
            $teasertype = $term->slug;{}
            $i++;
       
        }
    
        // BUTTON SWITCH //
        if($teasertype){
        switch($teasertype){  
            case 'article':
                $ctaclass= "article";
                $ctatext= "Read Now";
    
    etc etc etc 

    When I use this snippet on another page that references these custom post types using a Post Object field, it throws an error when looking up the taxonomy:

    Warning
    : foreach() argument must be of type array|object, bool given in
    /Users/louis.plante/Local Sites/smartvaultcom/app/public/wp-content/themes/smartvault-wordpress-website/inc/snippets/_incl_resources–teaser.php
    on line
    17

    Code used:

    									<?php $post_objects = get_field('campaign_group1_item_resource'); ?>
    									<?php
    									if( $post_objects ):
    									foreach( $post_objects as $post): 
    										setup_postdata($post); //set new $post_object
    										get_template_part( 'inc/snippets/_incl_resources--teaser' );
    									endforeach;
    									wp_reset_postdata(); //reset global $post
    									endif;
    									?>
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.