Jump to content

Wordpress - Run through all options selected.


UncleCali

Recommended Posts

Hi. For those familiar with Wordpress, I have a custom page template that queries a custom post type. I added the author-skill options and wondering how I can get PHP to run through the author-skill options after the WP_Query?

So far it only shows results for year and the author-type.

 

<?php
/**
* Template Name: Authors template
* 
**/
?>
<?php get_header(); ?>

<div id="main" role="main">
  <div id="slide-header" class="authors"></div>
  <!-- <div id="slide-wrapper">
    	<div id="slider">
            <img width="960" height="315" src="<?php bloginfo("siteurl"); ?>/wp-content/uploads/2012/03/slider_1.jpg" class="attachment-post-thumbnail wp-post-image" alt="slider_1" title="slider_1">
            <img width="960" height="315" src="<?php bloginfo("template_url"); ?>/img/slider_2.jpg" class="attachment-post-thumbnail wp-post-image" alt="slider_1" title="slider_1">          
   		</div>
    </div>-->
  
  <div class="wrapper">
    <article>
      <h1>Authors</h1>
      <div id="author-filters">
        <div class="filter"><span>Search Authors: </span>
          <?php 
					$inc = "A";
					for($i = 0; $i < 26; $i++){ ?>
          <a href="<?php the_permalink(); ?>?letter=<?php echo $inc; ?>"><?php echo $inc; ?></a>
          <?php 
					$inc++;
				} ?>
        </div>
        <div class="clear"></div>
        <div class="author-filter">
          <form method="post" action="<?php the_permalink(); ?>" style="width: 594px;">
          Genre:
          <select name="author-skill" id="author-skill">
            <option value="">Please Select</option>
            <option value="Poet" <?php if(isset($_POST['btn-sort'])) { echo ($_POST["author-skill"] == "Poet") ? "selected='selected'": "";}else{ echo "selected='selected'";} ?>>Poet</option>
            <option value="Essayist" <?php echo ($_POST["author-skill"] == "Essayist") ? "selected='selected'": ""; ?>>Essayist</option>
            <option value="Playwright" <?php echo ($_POST["author-skill"] == "Playwright") ? "selected='selected'": ""; ?>>Playwright</option>
            <option value="Novelist"<?php echo ($_POST["author-skill"] == "Novelist") ? "selected='selected'": ""; ?>>Novelist</option>
            <option value="Philologist"<?php echo ($_POST["author-skill"] == "Philologist") ? "selected='selected'": ""; ?>>Philologist</option>
            <option value="Fiction Writer"<?php echo ($_POST["author-skill"] == "Fiction Writer") ? "selected='selected'": ""; ?>>Fiction Writer</option>
            <option value="Fiction Author"<?php echo ($_POST["author-skill"] == "Fiction Author") ? "selected='selected'": ""; ?>>Fiction Author</option>
            <option value="Journalist"<?php echo ($_POST["author-skill"] == "Journalist") ? "selected='selected'": ""; ?>>Journalist</option>
            <option value="Critic"<?php echo ($_POST["author-skill"] == "Critic") ? "selected='selected'": ""; ?>>Critic</option>
            <option value="Theater Critic"<?php echo ($_POST["author-skill"] == "Theater Critic") ? "selected='selected'": ""; ?>>Theater Critic</option>
            <option value="Literary Scholar"<?php echo ($_POST["author-skill"] == "Literary Scholar") ? "selected='selected'": ""; ?>>Literary Scholar</option>
            <option value="Fiction Author"<?php echo ($_POST["author-skill"] == "Fiction Author") ? "selected='selected'": ""; ?>>Fiction Author</option>
            <option value="Children's Author"<?php echo ($_POST["author-skill"] == "Children's Author") ? "selected='selected'": ""; ?>>Children's Author</option>
            <option value="Literary Organizer"<?php echo ($_POST["author-skill"] == "Literary Organizer") ? "selected='selected'": ""; ?>>Literary Organizer</option>
            <option value="Dramatist"<?php echo ($_POST["author-skill"] == "Dramatist") ? "selected='selected'": ""; ?>>Dramatist</option>
            <option value="Musician"<?php echo ($_POST["author-skill"] == "Musician") ? "selected='selected'": ""; ?>>Musician</option>
            <option value="Short Story Writer"<?php echo ($_POST["author-skill"] == "Short Story Writer") ? "selected='selected'": ""; ?>>Short Story Writer</option>
            <option value="Short Story Author"<?php echo ($_POST["author-skill"] == "Short Story Author") ? "selected='selected'": ""; ?>>Short Story Author</option>
            <option value="Prose Writer"<?php echo ($_POST["author-skill"] == "Prose Writer") ? "selected='selected'": ""; ?>>Prose Writer</option>
            <option value="Prose Author"<?php echo ($_POST["author-skill"] == "Prose Author") ? "selected='selected'": ""; ?>>Prose Author</option>
            <option value="Script Writer"<?php echo ($_POST["author-skill"] == "Script Writer") ? "selected='selected'": ""; ?>>Script Writer</option>
            <option value="Sci-Fi Author"<?php echo ($_POST["author-skill"] == "Sci-Fi Author") ? "selected='selected'": ""; ?>>Sci-Fi Author</option>
            <option value="Philosopher"<?php echo ($_POST["author-skill"] == "Philosopher") ? "selected='selected'": ""; ?>>Philosopher</option>
            <option value="Literary PR Publicist"<?php echo ($_POST["author-skill"] == "Literary PR Publicist") ? "selected='selected'": ""; ?>>Literary PR Publicist</option>
            <option value="Translator"<?php echo ($_POST["author-skill"] == "Translator") ? "selected='selected'": ""; ?>>Translator</option>
            <option value="Director"<?php echo ($_POST["author-skill"] == "Director") ? "selected='selected'": ""; ?>>Director</option>
            <option value="Publisher"<?php echo ($_POST["author-skill"] == "Publisher") ? "selected='selected'": ""; ?>>Publisher</option>
            <option value=""> - - </option>
          </select>
            Type:
            <select name="author-type" id="author-type">
              <option value="">Please Select</option>
		  <option value="Winner" <?php echo ($_POST["author-type"] == "Winner") ? "selected='selected'": "";?>>Winners</option>
              <option value="Nominee" <?php echo ($_POST["author-type"] == "Nominee") ? "selected='selected'": ""; ?>>Nominees (short list)</option>
              <option value="Contestant" <?php echo ($_POST["author-type"] == "Contestant") ? "selected='selected'": ""; ?>>Contestants (long list)</option>
              <option value=""> - - </option>
            </select>
            Year:
            <?php  $y = 2000;$yy =  "2011"; //date("Y"); ?>
            <select name="author-yr" id="author-yr">
              <option value="">Please Select..</option>
              <?php while($y<=$yy): ?>
              <option value="<?php echo $y; ?>" <?php if(isset($_POST['btn-sort'])) { echo ($y == $_POST['author-yr']) ? "selected='selected'": "";}else{ echo ($y == "2011") ? "selected='selected'": "";} ?>><?php echo $y; ?></option>
              <?php $y++;endwhile; ?>
              <option value=""> - - </option>
            </select>
            <input type="submit" id="btnsort" name="btn-sort" value=" " >
          </form>
        </div>
      </div>
      <?php $authors=new WP_Query('post_type=author&order=asc&posts_per_page=999'); ?>
      <?php if($authors->have_posts()): ?>
      <ul id="authors-sandbox">
        <?php while($authors->have_posts()): $authors->the_post(); ?>
        <?php  
                        $skills = get_post_meta(get_the_ID(),'author-skill',true); 
                        $author_type = get_post_meta(get_the_ID(),'author-type',true);
                        $yr = get_post_meta(get_the_ID(),'competition-year',true);
					if(isset($_POST['btn-sort'])){
						if(!empty($_POST['author-type']) && empty($_POST['author-yr'])){
							if($author_type != $_POST['author-type'] ) continue;
						}
						elseif(!empty($_POST['author-yr']) && empty($_POST['author-type'])){
							if($yr != $_POST['author-yr'] ) continue;
						}
						elseif(!empty($_POST['author-yr']) && !empty($_POST['author-type'])){
							if($yr != $_POST['author-yr'] || $author_type != $_POST['author-type']) continue;
						}
					}
					elseif(!empty($_GET['letter']) && !isset($_POST['btn-sort'])){
						$name = get_the_title(get_the_ID());												
						$name = explode(" ",$name);
						if($name[1][0] != $_GET['letter']) continue;


					}
					elseif(empty($_GET['letter']) && !isset($_POST['btn-sort'])){
						if($yr != "2011" || $author_type != "Winner"){
							continue;								
						}

					}
                    
                    ?>
        <li class="<?php echo $author_type ?> alpha-<?php echo substr(get_the_title(),0,1)  ?> yr-<?php echo $yr; ?> "> <a class="author_anchor" href="<?php the_permalink(); ?>">
          <?php the_post_thumbnail('author-thumb') ?>
          <a href="<?php the_permalink(); ?>">
          <?php the_title(); ?>
          </a>
          <p><?php echo $skills; ?></p>
          </a> </li>
        <?php endwhile; ?>
      </ul>
      <?php endif; wp_reset_postdata(); ?>
    </article>

    <?php get_sidebar(); ?>
    <div class="clearfix"></div>
  </div>
</div>
<?php get_footer(); ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.