Custom taxonomy template not working with simple loop. Multiple CPT using the same taxonomy

WP defaults to showing normal native Posts in archives. It won’t automagically pick up which post types you want in your archive. You will have to adjust main query for it to explain that to it, with something like: add_action( ‘pre_get_posts’, function ( WP_Query $query ) { if ( $query->is_main_query() && $query->is_tax( ‘department’ ) ) … 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

Display page of custom posts?

I think your problem is in the exact code that you’ve mentioned. pre_get_post is a bastard if you don’t use it correctly. With any archive type conditions used in pre_get_posts, it will affect both front end and back end. This include archives pages, category and taxonomy pages, tag pages and author pages. You’ll need to … Read more

Pagination problems with multiple custom post type archive pages

Your problem comes from a fundamental misunderstanding of how WordPress loads the main loop. Here you have a main query that goes and grabs the posts to display in your post type archive. It then decides to load archive-recept.php based on that query. The call to paginate_links then provides the pagination for that main query. … Read more

Archive template for taxonomy terms

I want to document this because I just found the answer recently. The problem with having taxonomy is that most developers have the mindset of expecting the taxonomy to be seen inside the post_type url of: http://hostname/post_type/taxonomy_term Instead, you are going to find the url in: http://hostname/taxonomy_slug/taxonomy_term This means that we often may be creating … Read more

Change number of posts to show on Archive page (custom post type)

Just make sure you’re not in the admin when changing the query: function num_posts_archive_project_ie($query) { if (!is_admin() && $query->is_archive(‘projects-ie’) && $query->is_main_query()) { $query->set(‘posts_per_page’, 6); } return $query; } is_admin() does return true only if you’re in the backend (it does not, however, verify that the current user is an admin user, despite the name, don’t … Read more

Loading custom page template via plugin

To add custom template in page attributes template section you have to first add your template to dropdown and load it in template_include hook when current page has selected it as current template. /** * Add “Custom” template to page attirbute template section. */ function wpse_288589_add_template_to_select( $post_templates, $wp_theme, $post, $post_type ) { // Add custom … Read more

Add custom field to the archive page?

Using the Advanced Custom Fields plugin you can assign options pages to you custom posttype like this: if( function_exists(‘acf_add_options_page’) ) { acf_add_options_page(array( ‘page_title’ => ‘YOUR_PAGE_TILE Options’, ‘menu_title’ => ‘YOUR_MENU_TITLE Options’, ‘menu_slug’ => ‘options_YOUR_SLUG’, ‘capability’ => ‘edit_posts’, ‘parent_slug’ => ‘edit.php?post_type=YOUR_CUSTOM_POSTTYPE_SLUG’, ‘position’ => false, ‘icon_url’ => ‘dashicons-images-alt2’, ‘redirect’ => false, )); } That way you get an … 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

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