Home Forums General Issues CPT with default taxonomy and ACF


CPT with default taxonomy and ACF

    • brnteka

    • November 18, 2020 at 5:58 am

    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?

    • brnteka

    • November 18, 2020 at 6:42 am

    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.

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.