Tag Info

Hot answers tagged

14

After you have set a static page as your home page you can add this to your functions.php and you are good to go. This will call the archive-POSTTYPE.php template correctly as well. add_action("pre_get_posts", "custom_front_page"); function custom_front_page($wp_query){ //Ensure this filter isn't applied to the admin area if(is_admin()) { ...


6

try 'has_archive' => 'true'; and do the permalink reset before testing! and it should be singular archive-job.php rather than archives-job.php


6

I know this is old but I have this problem too and I found a rather clean way to handle it is to use a custom menu walker class KB_Custom_Menu_Walker extends Walker_Nav_Menu { protected static $custom_post_types = array(); public function start_el(&$output, $item, $depth=0, $args=array(), $id=0) { if (isset( self::$custom_post_types[ ...


6

The has_archive parameter for register_post_type() does exactly what you expect it to do. However, it modifies rewrite rules when set. So, if you change it to false, you'll need to flush your rewrite rules in order for the archive index display to be removed entirely.


5

Given the standard registration, you should have the following: A post type with the name 'recipe' A recipe post archive at example.com/recipe/ Recipe posts with urls that take the form example.com/recipe/helloworldrecipe/ A template archive-recipe.php A template single-recipe.php However, I see this in your registration code: 'rewrite' => ...


5

your best opption is custom link with full url as Custom post types archives are different form taxonomy based archives (categories,tags,any custom taxonomy) and date based archives which have there own archive slug.


4

Include your template files in your plugin. I stick mine in /plugin/templates. You need to hook into template location for that template: add_filter('archive_template', 'yourplugin_get_custom_archive_template'); function yourplugin_get_custom_archive_template($template) { global $wp_query; if (is_post_type_archive('yourCPT')) { ...


4

To get the current post type use get_post_type(). Then ask get_post_type_object() for all the data you need, for example the slug: $post_type = get_post_type(); if ( $post_type ) { $post_type_data = get_post_type_object( $post_type ); $post_type_slug = $post_type_data->rewrite['slug']; echo $post_type_slug; }


4

Hook into '404_template'. (Example) Fetch all public custom post types where has_archive is not FALSE. Find the post type’s has_archive string and see if it is part of the current request’s url. Try get_page_by_title() with the last part of the requests. wp_redirect() to the found post’s permalink. exit;.


3

This should work for you: // grab all public post types $post_types = get_post_types( array('public' => true), 'names' ); // loops through each post type foreach( $post_types as $type ) { // setup the query $query_args = array( 'post_type' => $type, 'posts_per_page' => 1 ); // perform the query $items = ...


3

Why don't you try using a home.php file and place your desired loop/query within that file or alternatively use get_template_part to retrieve a file that contains your loop. Can you please show us your code? What I frequently do is structure my index.php like so, <?php get_header(); ?> <?php if ( is_home() ) { ...


3

You can use getarchives_where hook of wp_get_archives() function Add this function to your functions.php: function Cpt_getarchives_where_filter( $where , $r ) { $post_type = 'blog'; return str_replace( "post_type = 'post'" , "post_type = '$post_type'" , $where ); } Then when you want your monthly archive put this: add_filter( 'getarchives_where' , ...


3

If you'd like to list the individual courses, i.e. the taxonomy terms, you'd use neither WP_Query nor the WP standard Loop. Instead, make use of the get_terms function to retrieve the courses. It returns an array of term objects (if the taxonomy does exist and has terms matching the function arguments). Iterate over that and do something with it, such as ...


3

That's because 'meta_key' and 'meta_value' are not public query vars. In other words, you can't use them in URLs directly, nor should you. Instead, register a specific query var, like so: function register_my_qv() { global $wp; $wp->add_query_var( 'my_qv' ); } add_action( 'init', 'register_my_qv' ); Then, you can go to a URL like this: ...


3

How did you create the link with your category '39'? Is it a custom taxonomy? Here's the test i just did and it works fine: In functions.php i created the custom post type 'recipe': add_action( 'init', 'create_recipe' ); function create_recipe() { register_post_type( 'recipe', array( 'labels' => array( 'name' ...


3

Replace your code with the following. I have made some changes to the post_type_link filter's callback function. function my_custom_post_work() { $labels = array( 'name' => _x( 'Work', 'post type general name' ), 'singular_name' => _x( 'Work', 'post type singular name' ), 'add_new' => _x( ...


3

This conflict normally happens when a custom post type archive and a normal wordpress page has the same slug. The custom post type archive has the higher priority here. If you have a custom post type by the name 'Projects' and 'has_archive' is set to true for the custom post type then the conflict will arise. Set 'has_archive' to false so that it shows the ...


3

Try this piece of code for page template. I've used it on one of my projects. It outputs taxonomy term one by one with list of all posts with this term. (Just replace YOUR_TAXONOMY_SLUG to yours) <div id="content"> <h2 class="entry-title"><?php the_title(); ?></h2> <div id="post-<?php the_ID(); ?>" <?php post_class(); ...


3

I did something similar for a client a while back, I'll give you some of the code here as-is that you can possibly adapt to your needs. I'll warn you, it's quite a bit to parse through! First, I set up some custom rewrite rules to get the year/month URL structure and some query vars to pass the year and month to my template. In this example I have a page ...


3

as determined in the comments, the page URI is ?post_type=photos&genre=boudoir... The reason why "archive-{$post_type}.php" isn't used in this case is because the page is a taxonomy archive and not a custom post type archive. WordPress is looking for taxonomy-genre.php instead of archive-photos.php, and not finding it, is defaulting back to good old ...


2

Go to Settings->permalinks and change the permalink structure to Default. After saving the permalink as default revert it to custom structure or post name, it should work and i have tested this. I hope this can help you.


2

wp_list_categories uses get_term_link to retrive the terms link. This function have a filter that you can use to change what is returned. A problem is that you have to pass the current post type to the function that hooks into the filter, but a global variable should works for the scope. Of course you have to remove filter after all wp_list_categories ...


2

Unlike page templates, WordPress doesn't look in subdirectories for post template pages. The base function used for locating such templates is locate_template() (see source), which looks in the root directory of your theme (and parent theme). (On the other hand get_page_templates() searches sub-directory). You can use template_include filter (which ...


2

Updated approach The first thought/suggestion I made actually - like you said - doesn't work as I understood it. At least I tried it and couldn't figure it out. That said, what you want is still achievable, but not by using a endpoint or at least not by making use of add_rewrite_endpoint(). However I figured it should be possible via a "ordinary" rewrite ...


2

add_filter( 'template_include', 'wpsites_cpt_archive_page_template', 99 ); function wpsites_cpt_archive_page_template( $template ) { if ( is_post_type_archive() ) { $new_template = locate_template( array( 'your-cpt-template.php' ) ); if ( '' != $new_template ) { return $new_template ; } } return $template; ...


2

You can use the archive_template hook to process the content of a theme's archive template, by using the scheme below, but obviously you'll only ever be able to process a fraction of the themes out there, given that a template can basically contain any old thing. The scheme is to load the template into a string ($tpl_str) in the archive_template filter, ...


2

I'm posting my comment to @MarkKaplun as part of my answer. My point is this, every end user experience a certain thing in a certain way based on his/her own knowledge, experience, usability and personal preference. There can never be a wrong or right answer here. Option one might suite you best, option two might suite me better. I like the way the OP ...


2

I've been able to solve this myself. My entire code for registering the CPT: <?php add_action( 'init', 'events_post_type_register' ); function events_post_type_register() { $post_type = "events"; $labels = array( 'name' => _x('Events', 'post type general name', 'project_X'), 'singular_name' => _x('Event', 'post type ...


2

It's still early for me, but you need to check for if( $events_query->have_posts() ) : rather than if( have_posts ) : as the latter will be checking against the current post type and not your custom query.


2

you can query_posts and orderby=title: <?php //*The Query*// $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; query_posts($query_string . '&post_type=YOUR-POST-TYPE&posts_per_page=1&orderby=title&order=asc&paged='.$paged); if(have_posts()) : while(have_posts()) : the_post(); ?> <?php endwhile; ?> ...



Only top voted, non community-wiki answers of a minimum length are eligible