Customized post loops olatechproJune 8, 20231 Views Let say I have one default post category and one custom category called âmy_nameâ. EDIT Post Views: 1 Related postsGet rid of this Strict Standards warningWooCommerce: get_current_screen not working with multi languageCan’t login on WordPressForce HTTPS using .htaccess – stuck in redirect loopWordPress: Ajax not working to insert, query and result dataHow Can I pass an image file to wp_handle_upload?
Here is the code. I don’t have the exact code right now but it helps a lot to you. $args = array( 'post_type' => 'post', 'posts_per_page' => 20, 'orderby' => 'date', 'order' => 'DESC' ); $loop = new WP_Query( $args ); $catDefaultArray = array(); $catBArray = array(); foreach ($loop as $post) { if($post->post_category == "default"){ $catDefaultArray[] =$post; } else if($post->post_category == "B"){ $catBArray[] = $post; } } $finalArray = array(); $j = 0; for($i = 0 ; $i < count($catDefaultArray) ; $i++){ if($i % 3 == 0){ $finalArray[] = $catDefaultArray[$i]; } else { $finalArray[] = $catBArray[$j]; $j++; } }
Here is the code.
I don’t have the exact code right now but it helps a lot to you.