Advertisement
Guest User

Untitled

a guest
Sep 16th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <?php
  2. $posts = $wp_query->posts; // Gets all post data from the main query
  3.  
  4. $c = []; // Going to hold an array of new keys for later use
  5. if ( have_posts() ) {
  6. $count = 0; //Start the counter
  7. $ppp = get_option('posts_per_page'); // Gets the backend posts per page option set. Will be used in conjustion with the counter
  8.  
  9. while ( have_posts() ) {
  10. the_post();
  11. if(has_tag('test')) { // This will be the tag to test against, your desired tag
  12. $c[] = $count++;
  13. }else{
  14. $c[] = $ppp + $count++; // Adds posts per page value to each count to advance posts without desired tag past desired tag
  15. }
  16. }
  17. }
  18. $posts_reordered = array_combine( $c, $posts ); // Reset each post from main query's key with the new keys created by $c
  19. $sort_posts = ksort($posts_reordered); // Sort the new array according to key
  20. /* ?><pre><?php var_dump($posts_reordered); ?></pre><?php */ // Uncomment to dump your array to get objects
  21.  
  22. foreach ($posts_reordered as $value) {
  23. echo '<h1>' . $value->post_title . '</h1>';//This will be your new loop
  24. echo get_the_post_thumbnail( $value->ID);
  25. echo apply_filters( 'the_content', $value->post_content );
  26. }
  27. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement