Support

Account

Home Forums Front-end Issues ACF Mutli Taxonomy with WP Query

Unread

ACF Mutli Taxonomy with WP Query

  • I have a custom field in flexible content that lets admin choose the categories for the page blog (standard Posts) using multi-checkbox.

    I’ve tried to output this on the front end with;

    <?PHP 
        $terms = get_sub_field('category');
    
        $args = array( 
            'posts_per_page' => get_sub_field('number_of_articles'),
            'order' => 'DESC',
            // 'cat' => '119,77'
            'cat' => $terms
        );
        $loop = new WP_Query( $args );
        while ( $loop->have_posts() ) : $loop->the_post(); 
    ?>
        <?php get_template_part( 'components/blog_article' ); ?>
    <?php endwhile; ?>      
    <?php wp_reset_query(); ?>

    And get an error and can’t seem to find a solution that’s been done before.

    I know I can get the list of categories using;

    <?php 
    	$terms = get_sub_field('category');
    	if( $terms ): 
    ?>
        <?php foreach( $terms as $term ): ?>
            <p><?php echo esc_html( $term->term_id ); ?></p>
        <?php endforeach; ?>
    <?php endif; ?>

    But struggling to work out how to merge the two…

Viewing 1 post (of 1 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.