Making next_posts_link(); return posts by month

You have to modify the query that selects the posts to select by month. This bit of code placed in the template will get the page number and subtract that from the current month. <?php $page = get_query_var(‘paged’) ? get_query_var(‘paged’) : 1; $subtractor = $page-1; $date = date(“Y-m-d H:i:s”); $current_month = date(‘n’, strtotime($date.’-‘.$subtractor.’months’)); $current_year = … Read more

How to make a custom Archive Page

You can get the queried date from the query vars in the $wp_query object: if( is_date() ){ if( isset( $wp_query->query_vars[‘year’] ) ){ echo ‘queried year is ‘ . $wp_query->query_vars[‘year’]; } if( isset( $wp_query->query_vars[‘monthnum’] ) ){ echo ‘queried month is ‘ . $wp_query->query_vars[‘monthnum’]; } if( isset( $wp_query->query_vars[‘day’] ) ){ echo ‘queried day is ‘ . $wp_query->query_vars[‘day’]; … Read more

How to get the date dynamically from archive.php to date.php?

It’s working very fine after I made some changes / adding on two php files function.php and date.php function.php function wpa_date_posts_per_page( $query ) { if ( !is_admin() && $query->is_date() && $query->is_main_query() ) { $query->set( ‘posts_per_page’, -1 ); } } add_action( ‘pre_get_posts’, ‘wpa_date_posts_per_page’ ); date.php <?php get_header(); while (have_posts()) : the_post(); echo the_title() . ‘<br/><br/>’; endwhile; … Read more

Archive filtering posts by year and month

That’s trivial, we can exploit how WordPress URLs work and pass the query vars directly in the URL: <form action=”/” method=”GET”> <select name=”year”> <option value=”2017>2017</option> … etc .. </select> <select name=”month”> <option value=”01>01</option> … etc .. </select> <input type=”submit” value=”Filter”/> </form> WP will then see that it’s a date archive, it may even 301 redirect … Read more

How to show specific year archive into dropdown list

<?php function foo($where) { return $where . ‘ AND YEAR(post_date) = 2010 ‘; } add_filter(‘getarchives_where’, ‘foo’, 1, 10); ?> <select name=”archive-dropdown” onChange=”document.location.href=this.options[this.selectedIndex].value;”> <option value=””><?php esc_attr_e( __(‘Select Issue’) ); ?></option> <?php wp_get_archives(‘type=daily&format=option’); ?> </select> <?php remove_filter(‘getarchives_where’, ‘foo’, 1, 10); ?>

Output yearly archive within a page

You can just use a normal query to grab all posts (which are, by default, sorted date descending), and break them up as you loop over them: <?php $posts = new WP_Query( array( ‘posts_per_page’ => -1, ‘post_type’ => ‘press-releases’ ) ); if ( $posts->have_posts() ) : ?> <ul class=”accordion”><?php while ( $posts->have_posts() ) : $posts->the_post(); … Read more

Including post_type = ‘wiki’ in author archives

Author archives default to searching for posts of the post type post. You could override this with wiki like so; function wpse_11210_set_wiki_for_author( $query ) { if ( $query->is_main_query() && $query->is_author() ) $query->set( ‘post_type’, ‘wiki’ ); } add_action( ‘pre_get_posts’, ‘wpse_11210_set_wiki_for_author’ ); Drop it in your a plugin or your theme’s functions.php (if the file doesn’t exist, … Read more

Sort custom-posts in archive.php via meta-key?

Just use the appropriate conditionals: function change_order_for_events( $query ) { //only show future events and events in the last 24hours $yesterday = current_time(‘timestamp’) – 24*60*60; if ( $query->is_main_query() && (is_tax(‘event_type’) || is_post_type_archive(‘wr_event’)) ) { $query->set( ‘meta_key’, ‘_wr_event_date’ ); $query->set( ‘orderby’, ‘meta_value_num’ ); $query->set( ‘order’, ‘ASC’ ); //Get events after 24 hours ago $query->set( ‘meta_value’, $yesterday … Read more

How do I make wp_get_archives show me months where only pages were created?

The wp_get_archives() function runs a filter on its WHERE clause–it’s called getarchives_where. You could use this to modify the query to only include pages rather than posts (which is the hard-coded default). I haven’t tested this yet, but try it out: add_filter(‘getarchives_where’,’my_archives_filter’); function my_archives_filter($where_clause) { return “WHERE post_type=”page” AND post_status=”publish””; } Then, just use the … Read more