Title: Custom archive.php using custom field
Last modified: August 19, 2016

---

# Custom archive.php using custom field

 *  [detectiveupdate](https://wordpress.org/support/users/detectiveupdate/)
 * (@detectiveupdate)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/custom-archivephp-using-custom-field/)
 * Well, after many search, I found that one way of doing that is to use `query_posts('
   meta_key=color&meta_value=blue');` just before `if (have_posts()) :` to make 
   it `query_posts('meta_key=color&meta_value=blue'); if (have_posts()) :`
 * The problem, this will change the default behaviour of my archive.php.
 * What I have in the beginning of my archive.php is (theme News Magazine Theme 
   640)
 *     ```
       <?php
       is_tag();
       if (have_posts()) :
       ?>
   
       <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
       <?php /* If this is a category archive */ if (is_category()) { ?>
       <h1> ‘<?php single_cat_title(); ?>’ <?php _e("Archives",'NewsMagazineTheme640'); ?></h1>
       <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
       <h1><?php _e("Posts Tagged",'NewsMagazineTheme640'); ?> ‘<?php single_tag_title(); ?>’</h1>
       <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
       <h1><?php _e("Archive for",'NewsMagazineTheme640'); ?> <?php the_time('F jS, Y'); ?></h1>
       <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
       <h1><?php _e("Archive for",'NewsMagazineTheme640'); ?> <?php the_time('F, Y'); ?></h1>
       <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
       <h1><?php _e("Archive for",'NewsMagazineTheme640'); ?> <?php the_time('Y'); ?></h1>
       <?php /* If this is an author archive */ } elseif (is_author()) { ?>
       <h1><?php _e("Author Archive",'NewsMagazineTheme640'); ?></h1>
       <?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
       <h1><?php _e("Blog Archives",'NewsMagazineTheme640'); ?></h1>
       <?php } ?>
       ```
   
 * What I see here, I am having different archive page based on different conditions
   passed through different functions here, like `is_author()`, `is_year()`, etc.
   Logically, thus if we have another function like `is_special($meta_key)` we could
   use the existing archive page for displaying post filtered by their special field
   values.
 * The questions:
    - Now, where can I create that function? In function.php?
    - Then, how to make the page understand that now he should use `is_special($
      meta_key)` function, and not another one?
    - Next question, how to pass the variable now that I am using `the_permalink()`
      for url generation?
    - How can I keep the pagination function.
 * Any help will be appreciated. Sorry if I have bombarded with too many shots.

Viewing 1 replies (of 1 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/custom-archivephp-using-custom-field/#post-1553238)
 * I am not sure that you want to modivy archive.php. The code you showed only changes
   the title of the page, not the actual query.
 * Have you considered making a template for your special archive and assigning 
   it to a Page which is called for that purpose?

Viewing 1 replies (of 1 total)

The topic ‘Custom archive.php using custom field’ is closed to new replies.

## Tags

 * [archive.php](https://wordpress.org/support/topic-tag/archive-php/)
 * [meta key](https://wordpress.org/support/topic-tag/meta-key/)
 * [meta value](https://wordpress.org/support/topic-tag/meta-value/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [15 years, 11 months ago](https://wordpress.org/support/topic/custom-archivephp-using-custom-field/#post-1553238)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
