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)

The topic ‘ACF Mutli Taxonomy with WP Query’ is closed to new replies.