Wordpress - Adding special classes to a specific term loop
<p>I want to loop through all posts for a custom post type however whilst looping them add a class to the posts that are tagged with a certain term.</p>

<p>I currently have the below function however this only grabs posts with the specific term and not all of the posts along side.</p>

<pre><code>/**
 * Get posts of particular termID
*/

function post_type_tax_query($post_type=null, $taxonomy=null, $term_id=null){

    $args = array(
        'posts_per_page'  =&gt; -1,
        'post_type'       =&gt; $post_type,
        'orderby'         =&gt; 'post_date',
        'order'           =&gt; 'DESC',
        'tax_query' =&gt; array(
            array(
                'taxonomy' =&gt; $taxonomy,
                'field' =&gt; 'id',
                'terms' =&gt; $term_id
            )
        )
    );

    $the_query = new \WP_Query( $args );
    $queryitems = $the_query-&gt;get_posts();

    return $queryitems;

}
</code></pre>

<p>My current loop with the above</p>

<pre><code>            $projects_posts = post_type_tax_query('projects', 'locked', '5');
                if($projects_posts){ ?&gt;
                    &lt;ul class="full-width projects-grid grid list-style-none"&gt;
                    &lt;?php $counter = 1; ?&gt;
                    &lt;?php foreach ($projects_posts as $project):
                            $project_title = get_field('project_title', $project-&gt;ID ); // get all the rows
                            $project_image_thumbnail = get_field('project_thumbnail_image', $project-&gt;ID); ?&gt;
                            &lt;li class="animation-element bounce-up delay-motion-&lt;?php echo $counter; ?&gt; col-lg-4 col-xs-12 col-sm-6"&gt;
                                &lt;a href="&lt;?php echo the_permalink($project-&gt;ID); ?&gt;" target="_blank"&gt;
                                    &lt;figure class="effect-milo"&gt;
                                        &lt;img src="&lt;?php echo $project_image_thumbnail; ?&gt;"/&gt;
                                        &lt;h4&gt;&lt;?= $project_title; ?&gt;&lt;/h4&gt;
                                    &lt;/figure&gt;
                                &lt;/a&gt;
                            &lt;/li&gt;
                    &lt;?php $counter++; ?&gt;
                    &lt;?php endforeach; ?&gt;
                    &lt;/ul&gt;
            &lt;?php } ?&gt;  
</code></pre>

<p>Just wondering how I could edit the above to ensure it loops through all posts, but applies a class to the specific posts with the term 5. This is for styling purposes.</p>

<p>Thanks,</p>

<p>DIM3NSION</p>