Title: WP_Query Fallback
Last modified: August 21, 2016

---

# WP_Query Fallback

 *  [jacksouthernweb](https://wordpress.org/support/users/jacksouthernweb/)
 * (@jacksouthernweb)
 * [12 years ago](https://wordpress.org/support/topic/wp_query-fallback/)
 * Ok, so I’ve got a custom taxonomy setup of ‘Writer’ and it’s a way to tie posts
   to an employee on the site but the client doesn’t want everyone to actually be
   setup as an author. So, on the employee profile pages I pull the posts with the
   employees name as the ‘Writer’, which works great. I’ve then got a fallback setup–
   code below.
 *     ```
       <?php
       // WP_Query arguments
       global $post;
       $slug = get_post( $post )->post_name;
   
       $args = array (
       	'posts_per_page'         => '1',
       	'writer'				 => $slug,
       );
   
       // The Query
       $query = new WP_Query( $args );
   
       // The Loop
       if ( $query->have_posts() ) {
       	while ( $query->have_posts() ) {
       		$query->the_post();
       		?>
       			// Do Stuff
       		<?php
       	}
       } else {
       	$fallbackargs = array (
       		'posts_per_page'         => '1',
       		'category'				 => 'featured',
       	);
   
       	$fallback = new WP_Query ( $fallbackargs);
       	while ( $fallback->have_posts() ) {
       		$fallback->the_post();
       		?>
       			// Do Stuff
       		<?php
       	}
       }
   
       // Restore original Post Data
       wp_reset_postdata();
       ?>
       ```
   
 * So, basically what I’m asking is this: Dear smarter people of the WordPress community–
   how can I do this more efficiently, or have I screwed up and done this semi-correctly?
   Thanks in advance!

The topic ‘WP_Query Fallback’ is closed to new replies.

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [jacksouthernweb](https://wordpress.org/support/users/jacksouthernweb/)
 * Last activity: [12 years ago](https://wordpress.org/support/topic/wp_query-fallback/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
