Ecommerce Shopify WordPress Discussion

php loop posts with 2 categories

I am building a WordPress theme for my personal website portfolio. I'm still learning as I go, with php. I'm looping posts and displaying their thumbnails and titles on my category archive pages. I would like to show posts of a specific category first, so I gave them a category of 'special', besides their original category/ies. The way I though of doing this was: · If -> the category has posts that also have the category 'special': display those; · After that -> display the posts from the original category that haven't been displayed yet. My first attempt looped all the posts from the category 'special', and then loop again the category in question. But this displays all the posts from the category 'special', wether or not they have the category of that archive page, and then displays the posts from the original category, even if they are already displayed. <div class="projects-container"> <!-- Loop projects from the category 'Special' --> <?php $args = array( 'category_name' => 'Special', ); $query = new WP_Query( $args ); ?> <?php if ( $query -> have_posts() ) : ?> <?php while ( $query -> have_posts() : $query -> the_post(); ?> <!-- the content --> <?php endwhile; wp_reset_postdata(); endif; ?> <!-- Loop projects from the main category --> <?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?> <!-- the content --> <?php endwhile; endif; ?> </div> Thank you for your help in advance.
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.