I’ve been stuck on this for hours… I did a var_dump($list_items) right before if ( $list_items ) { and it turns up empty, but a var_dump($hold_tax_query) looks (to me) like it should.

if($selected_custom_taxonomies){

$hold_tax_query = array('relation' => 'OR');

foreach ( $selected_custom_taxonomies as $a_tax ) :     
array_push($hold_tax_query, array('taxonomy' => 'customtax', 'field' => 'slug', 'terms' => $a_tax->slug));
    endforeach; 

$list_items = get_posts(
    array(
        'posts_per_page' => -1,
        'post_type' => 'custompost',
        'tax_query' => $hold_tax_query,
    )
);
//never gets past here because $list_items is empty...
if ( $list_items ) {

    foreach ( $list_items as $post ) :
        setup_postdata( $post ); 
?>
        <h2></h2>
        <?php the_field('description'); ?>
 <?php
    wp_reset_postdata();
endforeach; 
}
}
?>

Something is wrong with the array $hold_tax_query because when I only use 1 taxonomy field, it retrieves the custom post type…

Read more here: Error get_posts with Custom Taxonomy and OR relation


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: