biltmore_garden_leaf-250x333I have been working with a very nice theme from Graph Paper Press called “Reportage.” I’ve been making a fair number of modifications for my client, particularly involving the custom post type, “portfolio.” There are a number of interesting features about using a custom post type in a theme. It allows one to apply special templates with special field and layout, designed for that particular post type. For example, if you advertise products with particular characteristics on your WordPress site, you should use a custom post type to distinguish your product pages from your other post types. Very commonly, a ‘portfolio’ post type is included in a theme, to support gallery and image-forward style.

For my client, a professor of architecture, we decided that the URL and other references should say “project” instead of “portfolio,” as this was a more meaningful term for her work. To simplify this change and not disrupt some sophisticated coding in this theme, I kept the name of the post_type as “portfolio” and just changed all of its labels in the register_post_type function. In addition, we decided to remove the custom taxonomies from the custom post type, in favor of the generally available categories and post tags. To make this change effective, I had to make two somewhat obscure changes to the theme code.

  1. Besides finding and changing textual references to “Portfolio” in theme titles, I had to modify echo get_the_term_list() for the footer in content-portfolio.php, to refer to the standard category and tag taxonomy terms, not the custom taxonomy, which I of course entirely commented out in lib/actions.php. Note: always check the error log, it has important things to tell you! It tipped me off to this problem.
  2. I discovered that the conventional category query was not including the custom post_type posts. This required a more in-depth bit of research to solve; I had to create a new filter in lib/filters.php.
//these two functions added by dbwebwork.com

function show_portfolio_in_category_page($sql) {
     if (is_category()) {
          $sql = str_replace("wp_posts.post_type = 'post'", "wp_posts.post_type = 
          ('portfolio' OR 'post')", $sql);
     }
     return $sql;
}
add_filter('posts_where', 'show_portfolio_in_category_page');

function show_portfolio_in_tag_page($sql) {
     if (is_tag()) {
          $sql = str_replace("wp_posts.post_type = 'post'", "wp_posts.post_type = 
          ('portfolio' OR 'post')", $sql);
     }
     return $sql;
}
add_filter('posts_where', 'show_portfolio_in_tag_page');

Hallelujah for Stack Overflow. I learn a lot by digging around.

In many cases it is useful for a custom post type to have its own taxonomy, but not always.