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

Custom post type archive sorted and grouped by date in post meta field

OK, so this problem has two parts: Make WordPress to sort these posts properly. Make WordPress to display them with all that grouping. 1. Sorting CPT by meta value on archive You can use pre_get_posts to achieve this. add_action( ‘pre_get_posts’, function ( $query ) { if ( is_post_type_archive( ‘event’ ) && $query->is_main_query() ) { $query->set( … Read more

Disable single pages and archives and keep preview

You can redirect, when someone tries to see the archive or the single of your custom post type, just redirect them to another page, just put this in your functions.php add_action( ‘template_redirect’, ‘theme_redirects’, 99 ); function theme_redirects() { if ( is_post_type_archive( ‘post_type_slug’ ) || is_singular( ‘post_type_slug’ ) ) { wp_redirect( ‘my_url’ ); die(); } } … Read more

How to show multiple post types on taxonomy archive?

As you point out, if you want separate loops for different post types you’ll need to use a separate WP_Query() for post type. In the template you can get the current term (ID) being viewed via: get_queried_object_id() (see source) $args = array( ‘post_type’ => ‘staff’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘themes’, ‘terms’ => get_queried_object_id(), … Read more

Filter query_posts by tag slug on “Tag Archive” page (when tag is 2 or more words)

The single_tag_title() function returns the tag title while you need the tag slug or ID for use in query_posts(). This should get you started: if ( is_tag() ) { $tag = get_queried_object(); $tag_title = $tag->name; // Same as single_tag_title() $tag_slug = $tag->slug; $tag_id = $tag->term_id; } http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters

How to create pagination on archive.php template

The solution was surprisingly simple as you can see below. Thanks for your help @Sally CJ and @Tom J Nowell. <?php get_header(); ?> <!– PAGE INTRODUCTION –> <div class=”container”> <h1 class=”page_title”><?php the_archive_title(); ?></h1> </div> <!– PAGE CONTENTS –> <div class=”container”> <div class=”row”> <!– POSTS –> <?php if ( have_posts() ) : while ( have_posts() ) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)