Include and Exclude Taxonomies From Archives & Feeds Using ‘pre_get_posts’

I’ll take another shot. The following should modify the main query, such that it will include in its loop any posts that belong to no term of the Edition custom taxonomy. add_filter(‘pre_get_posts’,’better_editions_archive’); function better_editions_archive( $query ) { if ( $query->is_tax( ‘edition’ ) && $query->is_main_query() ) { $terms = get_terms( ‘edition’, array( ‘fields’ => ‘ids’ ) … Read more

Why are posts from custom post type not displayed in “category” archive?

You need to hook into the query because the category archive page explicitly only includes the ‘post’ type and nothing else. function namespace_add_custom_types( $query ) { if( (is_category() || is_tag()) && $query->is_archive() && empty( $query->query_vars[‘suppress_filters’] ) ) { $query->set( ‘post_type’, array( ‘post’, ‘myposttime’ )); } } add_action( ‘pre_get_posts’, ‘namespace_add_custom_types’ ); Modified from this article on … Read more

Get list of years when posts have been published

Your question is pretty old, but I just wanted to add a real solution to your question. Here’s a function that will return an array of years you have posts published in. You can put this function in functions.php or in a plugin or whatever you want. function get_posts_years_array() { global $wpdb; $result = array(); … Read more

How to get the custom post type from an archive page?

There are a several of ways to do this. Put: var_dump($wp_query->query,get_queried_object()); die; In your archive.php and you should see two of those ways. $wp_query->query will have post_type component for custom post types. That will not be there for post post types. get_queried_object will return quite a bit of data for custom post types but null … Read more

get term archive url / link

Use get_term_link e.g. to print out a list of actors terms linking to the archives: $terms = get_terms(‘actors’); echo ‘<ul>’; foreach ($terms as $term) { echo ‘<li><a href=”‘.get_term_link($term).'”>’.$term->name.'</a></li>’; } echo ‘</ul>’; However! If what you really mean is the equivilant of the custom post type archive, that lists all the posts of that type, but … Read more

Permalink Structure for Multiple Post Type Archives by Taxonomy

Here is part of the code from one of my projects to setup a similar structure for permalinks (same base slug for both the post type and the taxonomy archives), please note the values of ‘has_archive’ and ‘rewrite’ parameters of both the post type and the taxonomy: add_action( ‘init’, ‘register_my_post_types’ ); function register_my_post_types() { register_post_type( … Read more

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