1
Good morning! I’m not able to implement a forech in a database search using the native variables of wordpress, searching found something similar however is not what I need.
<?php global $post;
$args = array('category' => 17);
$custom_posts = get_posts($args);
foreach($custom_posts as $post) : setup_postdata($post);
...
endforeach;
?>
I want to return the data in a list to change the class from the first search to the second, example below:
<?php global $post;
$args = array('category' => 17);
$custom_posts = get_posts($args);
foreach($custom_posts as $post) : setup_postdata($post);
<div class="divA">
</div>
<div class="divB">
</div>
endforeach;
?>
Returning:
<div class="divA">
Teste 1
</div>
<div class="divB">
Teste 2
</div>
<div class="divA">
Teste 3
</div>
<div class="divB">
Teste 4
</div>
Would it be possible?
Forgive the delay to answer, it worked perfectly just had to perform some adjustments like inserting an echo for the class to be displayed
– RonaldoM
I’m glad it worked out. Truth, I forgot the echo, I edited the answer.
– Felipe de Farias