Support

Account

Home Forums General Issues CPT with default taxonomy and ACF

Helping

CPT with default taxonomy and ACF

  • Good day, i have a custom post type which I would want to show on a default category taxonomy page, so I add it to the query like so

    function add_custom_post_type_to_query( $query ) {
    	if ( is_admin() || !$query->is_main_query() )
            return $query;
    
    	if ( is_category() || is_tag() )  {
                $query->set( 'post_type', array('custom_post_type') );
    	}
    	
    	return $query;
    }
    add_action( 'pre_get_posts', 'add_custom_post_type_to_query' );

    and after that all of my “the_field()” on said category page doesn’t show up their values. How can i add a CPT to a query and make ACF keep working?

  • ok, so i have managed to retrieve values with this code
    <?php echo get_field('field', get_queried_object()); ?>
    is this the only right way to do it in my situation?

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

You must be logged in to reply to this topic.